Class for handling small tasks. More...
#include <threading.h>
Classes | |
struct | TaskType |
Public Types | |
typedef void(CDECL_XS * | TaskFunction) (void *) |
A function prototype for a task. More... | |
Public Member Functions | |
void | addTask (TaskFunction func, void *param) |
Adds a task to a queue. More... | |
void | clear (void) |
Clears a queue. More... | |
int32_t | getLength (void) noexcept |
TaskThread () | |
~TaskThread () | |
![]() | |
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 int32_t | innerFunction (void) |
The inner function of the task thread. More... | |
![]() | |
virtual void | exitFunction (void) |
Virtual exit function. More... | |
virtual void | initFunction (void) |
Virtual initialization function. More... | |
XsThread | threadHandle () const |
Return the thread handle. More... | |
Private Attributes | |
bool | m_inFunc |
std::deque< TaskType > | m_queue |
Mutex | m_safe |
Additional Inherited Members | |
![]() | |
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... | |
Class for handling small tasks.
Use this class if you have small tasks that need to be performed out of the main thread The thread uses tasks supplied in a TaskType struct.
Definition at line 219 of file threading.h.
typedef void(CDECL_XS* xsens::TaskThread::TaskFunction) (void *) |
A function prototype for a task.
Definition at line 222 of file threading.h.
|
inline |
Definition at line 259 of file threading.h.
|
inline |
Definition at line 260 of file threading.h.
|
inline |
Adds a task to a queue.
func | The function to add |
param | The parameters to add |
Definition at line 270 of file threading.h.
|
inline |
Clears a queue.
Definition at line 285 of file threading.h.
|
inlinenoexcept |
Definition at line 278 of file threading.h.
|
inlineprotectedvirtual |
The inner function of the task thread.
The function checks if there is a task in the queue and executes it. Then it returns to the StandardThread main loop to check for termination. If there are no tasks in the queue, the thread will terminate itself.
Reimplemented from xsens::StandardThread.
Definition at line 241 of file threading.h.
|
private |
Definition at line 232 of file threading.h.
|
private |
Definition at line 230 of file threading.h.
|
private |
Definition at line 231 of file threading.h.