|
DESERT 4.0.0
|
#include <stoppable_thread.h>


Public Member Functions | |
| StoppableThread ()=default | |
| virtual | ~StoppableThread ()=default |
| bool | Start (bool exc_info=false) |
| void | Stop (bool wait=false) |
| virtual void | Run ()=0 |
| template<class Rep , class Period > | |
| void | Sleep (const std::chrono::duration< Rep, Period > &d) |
| bool | Running () |
| bool | StopRequested () |
Private Member Functions | |
| void | RunInternal () |
Private Attributes | |
| std::atomic_bool | m_running {false} |
| std::atomic_bool | m_stop {false} |
| std::thread | m_thread |
A stoppable C++11 thread implementation.
|
default |
|
virtualdefault |
|
pure virtual |
Pure virtual stopable worker function of thread, use the test StopRequested() to check if it should stop. Implementation example (use in derived class):
void Run() override { while (!StopRequested()) { Sleep(100ms); } }
Implemented in PositionListener< Owner >, and PositionListener< UDPPosition >.
Referenced by RunInternal().
|
inlineprivate |
|
inline |
Returns the current state of the thread.
References m_running.
Referenced by UDPPosition::command(), and Start().
|
inline |
Sleep for the given duration, use literals like 1s, 100ms, 10us
|
inline |
Start the thread.
| exc_info | prints a catched exception message to stderr |
References m_thread, RunInternal(), and Running().
Referenced by UDPPosition::command().

|
inline |
Stop the thread, needs call(s) to StopRequested() in the Run() worker function to check for the stop request.
| wait | wait for the thread to end |
References m_stop, and m_thread.
Referenced by UDPPosition::command().
|
inline |
Returns if a stop was requested.
References m_stop.
Referenced by PositionListener< Owner >::Run().
|
private |
Referenced by RunInternal(), and Running().
|
private |
Referenced by Stop(), and StopRequested().