Go to the documentation of this file.
16 #ifndef SURGSIM_FRAMEWORK_BASICTHREAD_H
17 #define SURGSIM_FRAMEWORK_BASICTHREAD_H
22 #include <boost/thread.hpp>
23 #include <boost/chrono.hpp>
51 explicit BasicThread(
const std::string& name =
"Unknown Thread");
68 void start(std::shared_ptr<Barrier> startupBarrier =
nullptr,
bool isSynchronous =
false);
105 m_period = boost::chrono::duration<double>(1.0 / val);
155 std::shared_ptr<SurgSim::Framework::Logger>
m_logger;
190 #endif // SURGSIM_FRAMEWORK_BASICTHREAD_H
bool isInitialized()
Query if this object is initialized.
Definition: BasicThread.cpp:65
bool m_isIdle
Definition: BasicThread.h:167
boost::thread & getThread()
Definition: BasicThread.cpp:102
Timer class, measures execution times.
Definition: Timer.h:30
bool setSynchronous(bool val)
Sets the thread to synchronized execution in concert with the startup barrier, the startup barrier ha...
Definition: BasicThread.cpp:265
bool isRunning() const
Query if this object is running.
Definition: BasicThread.cpp:70
bool initialize()
Trigger the initialization of this object, this will be called before all other threads doStartup() a...
Definition: BasicThread.cpp:75
std::shared_ptr< SurgSim::Framework::Logger > m_logger
Logger for this thread.
Definition: BasicThread.h:155
bool waitForBarrier(bool success)
Definition: BasicThread.cpp:256
virtual bool executeInitialization()
Definition: BasicThread.cpp:228
void setRate(double val)
Set the update rate of the thread.
Definition: BasicThread.h:103
bool startUp()
Trigger the startup of this object, this will be called after all other threads doInit() was called t...
Definition: BasicThread.cpp:82
bool isSynchronous()
Query if this object is synchronized.
Definition: BasicThread.cpp:274
virtual bool doInitialize()=0
Definition: CompoundShapeToGraphics.cpp:29
bool isIdle()
Query if this thread is in idle state or not.
Definition: BasicThread.cpp:218
std::string m_name
Definition: BasicThread.h:158
void stop()
Stopping the execution, blocks until the running thread has actually stopped,.
Definition: BasicThread.cpp:190
virtual void doBeforeStop()
Prepares the thread for its execution to be stopped.
Definition: BasicThread.cpp:299
bool m_isRunning
Definition: BasicThread.h:169
Basic thread implementation, tries to maintain a constant rate, supplies startup an initialization,...
Definition: BasicThread.h:48
virtual ~BasicThread() noexcept(false)
C++11 introduced noexcept.
Definition: BasicThread.cpp:51
void setIdle(bool isIdle)
Set/Unset the thread in an idle state (doUpdate() called or not in the update() method)
Definition: BasicThread.cpp:213
double getCpuTime() const
Definition: BasicThread.cpp:279
virtual bool doUpdate(double dt)
Implementation of actual work function for this thread, this has a default implementation to handle d...
Definition: BasicThread.cpp:294
void operator()()
This is what boost::thread executes on thread creation.
Definition: BasicThread.cpp:107
Timer m_timer
Timer to measure the actual time taken to doUpdate.
Definition: BasicThread.h:137
bool m_stopExecution
Definition: BasicThread.h:170
std::string getName() const
Definition: BasicThread.cpp:223
void resetCpuTimeAndUpdateCount()
Reset the cpu time and the update count to 0.
Definition: BasicThread.cpp:289
boost::thread m_thisThread
Definition: BasicThread.h:160
bool m_isSynchronous
Definition: BasicThread.h:171
boost::mutex m_mutexStartStop
Definition: BasicThread.h:165
bool m_isInitialized
Definition: BasicThread.h:168
std::shared_ptr< Barrier > m_startupBarrier
Definition: BasicThread.h:162
size_t getUpdateCount() const
Definition: BasicThread.cpp:284
BasicThread(const std::string &name="Unknown Thread")
Definition: BasicThread.cpp:31
virtual bool doStartUp()=0
void start(std::shared_ptr< Barrier > startupBarrier=nullptr, bool isSynchronous=false)
C++11 introduced noexcept.
Definition: BasicThread.cpp:87
boost::chrono::duration< double > m_period
Definition: BasicThread.h:161