16 #ifndef SURGSIM_FRAMEWORK_BASICTHREAD_H 17 #define SURGSIM_FRAMEWORK_BASICTHREAD_H 22 #include <boost/thread.hpp> 23 #include <boost/chrono.hpp> 25 #include "SurgSim/Framework/Barrier.h" 26 #include "SurgSim/Framework/Timer.h" 51 explicit BasicThread(
const std::string& name =
"Unknown Thread");
55 #if defined(_MSC_VER) && _MSC_VER < 1912 71 void start(std::shared_ptr<Barrier> startupBarrier =
nullptr,
bool isSynchronous =
false);
108 m_period = boost::chrono::duration<double>(1.0 / val);
137 bool ignoresExceptions()
const;
138 void setIgnoreExceptions(
bool val);
155 bool waitForBarrier(
bool success);
157 virtual bool executeInitialization();
160 std::shared_ptr<SurgSim::Framework::Logger>
m_logger;
165 boost::thread m_thisThread;
166 boost::chrono::duration<double> m_period;
167 std::shared_ptr<Barrier> m_startupBarrier;
170 boost::mutex m_mutexStartStop;
173 bool m_isInitialized;
175 bool m_stopExecution;
176 bool m_isSynchronous;
177 bool m_ignoreExceptions;
179 virtual bool doInitialize() = 0;
180 virtual bool doStartUp() = 0;
186 virtual bool doUpdate(
double dt);
190 virtual void doBeforeStop();
196 #endif // SURGSIM_FRAMEWORK_BASICTHREAD_H boost::thread & getThread()
Definition: BasicThread.cpp:105
Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
void start(std::shared_ptr< Barrier > startupBarrier=nullptr, bool isSynchronous=false)
Live cycle functions, public implementation.
Definition: BasicThread.cpp:90
void stop()
Stopping the execution, blocks until the running thread has actually stopped,.
Definition: BasicThread.cpp:200
void setRate(double val)
Set the update rate of the thread.
Definition: BasicThread.h:106
bool startUp()
Trigger the startup of this object, this will be called after all other threads doInit() was called t...
Definition: BasicThread.cpp:85
std::shared_ptr< SurgSim::Framework::Logger > m_logger
Logger for this thread.
Definition: BasicThread.h:160
Timer class, measures execution times.
Definition: Timer.h:31
std::string getName() const
Definition: BasicThread.cpp:233
bool setSynchronous(bool val)
Sets the thread to synchronized execution in concert with the startup barrier, the startup barrier ha...
Definition: BasicThread.cpp:274
bool isRunning() const
Query if this object is running.
Definition: BasicThread.cpp:73
bool initialize()
Trigger the initialization of this object, this will be called before all other threads doStartup() a...
Definition: BasicThread.cpp:78
virtual ~BasicThread() noexcept(false)
C++11 introduced noexcept.
Definition: BasicThread.cpp:54
Timer m_timer
Timer to measure the actual time taken to doUpdate.
Definition: BasicThread.h:142
void operator()()
This is what boost::thread executes on thread creation.
Definition: BasicThread.cpp:110
bool isSynchronous()
Query if this object is synchronized.
Definition: BasicThread.cpp:283
size_t getUpdateCount() const
Definition: BasicThread.cpp:293
Basic thread implementation, tries to maintain a constant rate, supplies startup an initialization...
Definition: BasicThread.h:48
bool isIdle()
Query if this thread is in idle state or not.
Definition: BasicThread.cpp:228
void setIdle(bool isIdle)
Set/Unset the thread in an idle state (doUpdate() called or not in the update() method) ...
Definition: BasicThread.cpp:223
double getCpuTime() const
Definition: BasicThread.cpp:288
bool isInitialized()
Query if this object is initialized.
Definition: BasicThread.cpp:68
void resetCpuTimeAndUpdateCount()
Reset the cpu time and the update count to 0.
Definition: BasicThread.cpp:298