Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
xsens::StandardThread Class Reference

A class for a standard thread that has to perform the same action repeatedly. More...

#include <threading.h>

Inheritance diagram for xsens::StandardThread:
Inheritance graph
[legend]

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
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ StandardThread()

xsens::StandardThread::StandardThread ( )

Constructor, creates the necessary signals. Does NOT start the thread.

Definition at line 89 of file threading.cpp.

◆ ~StandardThread()

xsens::StandardThread::~StandardThread ( )
virtual

Destructor, stops the thread if it was running and cleans up afterwards.

Definition at line 110 of file threading.cpp.

Member Function Documentation

◆ exitFunction()

virtual void xsens::StandardThread::exitFunction ( void  )
inlineprotectedvirtual

Virtual exit function.

Definition at line 116 of file threading.h.

◆ getThreadId()

XsThreadId xsens::StandardThread::getThreadId ( void  ) const
inline
Returns
The thread ID

Definition at line 142 of file threading.h.

◆ initFunction()

virtual void xsens::StandardThread::initFunction ( void  )
inlineprotectedvirtual

Virtual initialization function.

Reimplemented in PacketErrorRateEstimator, DataParser, and DataPoller.

Definition at line 113 of file threading.h.

◆ innerFunction()

virtual int32_t xsens::StandardThread::innerFunction ( void  )
inlineprotectedvirtual

◆ isAlive()

bool xsens::StandardThread::isAlive ( void  ) const volatile
noexcept
Returns
True if the thread is alive

Definition at line 140 of file threading.cpp.

◆ isRunning()

bool xsens::StandardThread::isRunning ( void  ) const volatile
noexcept

Returns whether the thread is currently running.

Definition at line 160 of file threading.cpp.

◆ isTerminating()

bool xsens::StandardThread::isTerminating ( ) const volatile
noexcept

Returns whether the thread should (have) terminate(d)

Definition at line 182 of file threading.cpp.

◆ setPriority()

bool xsens::StandardThread::setPriority ( XsThreadPriority  pri)

Sets the priority of the thread.

Parameters
priThe thread priority to set
Returns
True if successful

Definition at line 191 of file threading.cpp.

◆ signalStopThread()

void xsens::StandardThread::signalStopThread ( void  )
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.

◆ startThread()

bool xsens::StandardThread::startThread ( const char *  name = NULL)

Starts the thread.

Parameters
nameThe name of the thread as shown in the debugger, may be NULL in which case the system determines the name.
Returns
True if successful

Definition at line 281 of file threading.cpp.

◆ stopThread()

void xsens::StandardThread::stopThread ( void  )
noexcept

Tells the thread to stop and waits for it to end.

Definition at line 334 of file threading.cpp.

◆ threadCleanup()

void xsens::StandardThread::threadCleanup ( void *  obj)
staticprivate

Cleanup the thread by calling the exit function.

Definition at line 421 of file threading.cpp.

◆ threadHandle()

XsThread xsens::StandardThread::threadHandle ( ) const
inlineprotected

Return the thread handle.

Definition at line 125 of file threading.h.

◆ threadInit()

XSENS_THREAD_RETURN xsens::StandardThread::threadInit ( void *  obj)
staticprivate

Definition at line 409 of file threading.cpp.

◆ threadMain()

void xsens::StandardThread::threadMain ( void  )
private

The inner loop of the thread, calls innerFunction repeatedly and sleeps when necessary.

Definition at line 429 of file threading.cpp.

Member Data Documentation

◆ m_attr

pthread_attr_t xsens::StandardThread::m_attr
protected

Duplicates m_stop functionality for external dependent classes such as Semaphore.

Definition at line 101 of file threading.h.

◆ m_name

char* xsens::StandardThread::m_name
private

Definition at line 105 of file threading.h.

◆ m_priority

XsThreadPriority xsens::StandardThread::m_priority
private

Definition at line 87 of file threading.h.

◆ m_running

bool xsens::StandardThread::m_running
protected

Indicates that the thread is running.

Definition at line 102 of file threading.h.

◆ m_stop

volatile std::atomic_bool xsens::StandardThread::m_stop
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.

◆ m_thread

XsThread xsens::StandardThread::m_thread
private

Definition at line 86 of file threading.h.

◆ m_yieldOnZeroSleep

volatile std::atomic_bool xsens::StandardThread::m_yieldOnZeroSleep
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.


The documentation for this class was generated from the following files:


xsens_mti_driver
Author(s):
autogenerated on Sun Sep 3 2023 02:43:23