A class for a standard thread that has to perform the same action repeatedly. More...
#include <threading.h>
Public Member Functions | |
XsThreadId | getThreadId (void) const |
bool | isAlive (void) volatile const noexcept |
bool | isRunning (void) volatile const noexcept |
Returns whether the thread is currently running. More... | |
bool | isTerminating () volatile const noexcept |
Returns whether the thread should (have) terminate(d) More... | |
bool | setPriority (XsThreadPriority pri) |
Sets the priority of the thread. More... | |
virtual void | signalStopThread (void) |
Tells the thread to stop but does not wait for it to end. More... | |
StandardThread () | |
bool | startThread (const char *name=NULL) |
Starts the thread. More... | |
void | stopThread (void) noexcept |
Tells the thread to stop and waits for it to end. More... | |
virtual | ~StandardThread () |
Protected Member Functions | |
virtual void | exitFunction (void) |
Virtual exit function. More... | |
virtual void | initFunction (void) |
Virtual initialization function. More... | |
virtual int32_t | innerFunction (void) |
Virtual inner function. More... | |
XsThread | threadHandle () const |
Return the thread handle. More... | |
Protected Attributes | |
pthread_attr_t | m_attr |
Duplicates m_stop functionality for external dependent classes such as Semaphore. More... | |
bool | m_running |
Indicates that the thread is running. More... | |
volatile std::atomic_bool | m_stop |
Indicates that the thread should stop. Derived classes should check isTerminating() instead of directly polling this value when checking if the thread should stop. However, there are some cases (tests, SignallingThread) where direct access from within the class is desired, which is why the vlaue is protected instead of private. More... | |
volatile std::atomic_bool | m_yieldOnZeroSleep |
When true, a sleep value of 0 returned by innerFunction will trigger a thread yield operation. When false, the next cycle is started immediately. More... | |
Private Member Functions | |
void | threadMain (void) |
The inner loop of the thread, calls innerFunction repeatedly and sleeps when necessary. More... | |
Static Private Member Functions | |
static void | threadCleanup (void *obj) |
Cleanup the thread by calling the exit function. More... | |
static XSENS_THREAD_RETURN | threadInit (void *obj) |
Private Attributes | |
char * | m_name |
XsThreadPriority | m_priority |
XsThread | m_thread |
A class for a standard thread that has to perform the same action repeatedly.
The class has three virtual functions, of which the innerFunction is the most important. innerFunction gets called repeatedly and is expected to return so that StandardThread can check for thread termination.
Definition at line 83 of file threading.h.
xsens::StandardThread::StandardThread | ( | ) |
Constructor, creates the necessary signals. Does NOT start the thread.
Definition at line 89 of file threading.cpp.
|
virtual |
Destructor, stops the thread if it was running and cleans up afterwards.
Definition at line 110 of file threading.cpp.
|
inlineprotectedvirtual |
Virtual exit function.
Definition at line 116 of file threading.h.
|
inline |
Definition at line 142 of file threading.h.
|
inlineprotectedvirtual |
Virtual initialization function.
Reimplemented in PacketErrorRateEstimator, DataParser, and DataPoller.
Definition at line 113 of file threading.h.
|
inlineprotectedvirtual |
Virtual inner function.
Reimplemented in xsens::ThreadedFunction, Xs4FileTask::ReaderThread, xsens::PooledThread, RestoreCommunication, xsens::TaskThread, MtThread, PacketErrorRateEstimator, DataParser, and DataPoller.
Definition at line 119 of file threading.h.
|
noexcept |
Definition at line 140 of file threading.cpp.
|
noexcept |
Returns whether the thread is currently running.
Definition at line 160 of file threading.cpp.
|
noexcept |
Returns whether the thread should (have) terminate(d)
Definition at line 182 of file threading.cpp.
bool xsens::StandardThread::setPriority | ( | XsThreadPriority | pri | ) |
Sets the priority of the thread.
pri | The thread priority to set |
Definition at line 191 of file threading.cpp.
|
virtual |
Tells the thread to stop but does not wait for it to end.
Reimplemented in DataParser.
Definition at line 320 of file threading.cpp.
bool xsens::StandardThread::startThread | ( | const char * | name = NULL | ) |
Starts the thread.
name | The name of the thread as shown in the debugger, may be NULL in which case the system determines the name. |
Definition at line 281 of file threading.cpp.
|
noexcept |
Tells the thread to stop and waits for it to end.
Definition at line 334 of file threading.cpp.
|
staticprivate |
Cleanup the thread by calling the exit function.
Definition at line 421 of file threading.cpp.
|
inlineprotected |
Return the thread handle.
Definition at line 125 of file threading.h.
|
staticprivate |
Definition at line 409 of file threading.cpp.
|
private |
The inner loop of the thread, calls innerFunction repeatedly and sleeps when necessary.
Definition at line 429 of file threading.cpp.
|
protected |
Duplicates m_stop functionality for external dependent classes such as Semaphore.
Definition at line 101 of file threading.h.
|
private |
Definition at line 105 of file threading.h.
|
private |
Definition at line 87 of file threading.h.
|
protected |
Indicates that the thread is running.
Definition at line 102 of file threading.h.
|
protected |
Indicates that the thread should stop. Derived classes should check isTerminating() instead of directly polling this value when checking if the thread should stop. However, there are some cases (tests, SignallingThread) where direct access from within the class is desired, which is why the vlaue is protected instead of private.
Definition at line 93 of file threading.h.
|
private |
Definition at line 86 of file threading.h.
|
protected |
When true, a sleep value of 0 returned by innerFunction will trigger a thread yield operation. When false, the next cycle is started immediately.
Definition at line 94 of file threading.h.