Dawn Framework 1.0
Universal data acquisition framework for embedded systems
Classes | Public Member Functions | Static Public Attributes | Protected Member Functions | List of all members
dawn::CThreadedObject Class Reference

Portable thread owner abstraction for Dawn components. More...

#include <thread.hxx>

Inheritance diagram for dawn::CThreadedObject:
[legend]

Classes

struct  SThreadConfig
 Per-thread runtime configuration. More...
 

Public Member Functions

 CThreadedObject ()
 Constructor - initializes thread management state.
 
virtual ~CThreadedObject ()
 Destructor - cleans up thread resources.
 
const SThreadConfiggetThreadConfig () const
 Get current thread configuration.
 
int getThreadPriority () const
 Get configured worker thread priority.
 
int getThreadScheduler () const
 Get configured worker thread scheduler policy.
 
size_t getThreadStackSize () const
 Get configured worker thread stack size.
 
bool isRunning () const
 Check if the worker thread is running.
 
void setThreadConfig (const SThreadConfig &config)
 Replace the full thread configuration.
 
template<typename Func >
void setThreadFunc (Func &&func)
 Assign the function executed by threadStart().
 
void setThreadPriority (int priority)
 Configure worker thread priority.
 
void setThreadScheduler (int scheduler)
 Configure worker thread scheduler policy.
 
void setThreadStackSize (size_t stackSize)
 Configure worker thread stack size.
 
int threadStart ()
 Start the worker thread.
 
int threadStop ()
 Stop the worker thread.
 

Static Public Attributes

static int THREAD_PRIORITY_DEFAULT = 0
 Default thread priority behavior.
 
static int THREAD_SCHEDULER_DEFAULT = -1
 Default scheduler behavior.
 

Protected Member Functions

template<typename Func >
int startWorkerThread (Func &&func)
 Start the worker thread with a given function.
 
int stopWorkerThread ()
 Stop the worker thread.
 
CThreadedObjectworkerThread ()
 Get a reference to this thread controller.
 
const CThreadedObjectworkerThread () const
 Get a const reference to this thread controller.
 
bool workerThreadRunning () const
 Check if the worker thread is running.
 

Detailed Description

Portable thread owner abstraction for Dawn components.

Provides the low-level thread lifecycle API used by composed thread owners and the convenience helpers previously exposed by the mixin wrapper.

The worker thread is implemented with POSIX pthreads so Dawn can control stack size, scheduling policy, and priority on a per-thread basis. When no configuration is supplied, the OS default stack size and the creating thread's scheduler settings are used.

Definition at line 31 of file thread.hxx.

Member Function Documentation

◆ isRunning()

bool CThreadedObject::isRunning ( ) const

Check if the worker thread is running.

Returns
True if thread is running, false otherwise.

Definition at line 256 of file thread.cxx.

Here is the caller graph for this function:

◆ setThreadFunc()

template<typename Func >
void dawn::CThreadedObject::setThreadFunc ( Func &&  func)
inline

Assign the function executed by threadStart().

Parameters
funcCallable object to execute in the worker thread.

Definition at line 100 of file thread.hxx.

Here is the caller graph for this function:

◆ setThreadPriority()

void dawn::CThreadedObject::setThreadPriority ( int  priority)
inline

Configure worker thread priority.

Parameters
priorityRequested priority (0 = creator default).

Definition at line 149 of file thread.hxx.

References dawn::CThreadedObject::SThreadConfig::priority.

◆ setThreadScheduler()

void dawn::CThreadedObject::setThreadScheduler ( int  scheduler)
inline

Configure worker thread scheduler policy.

Parameters
schedulerPOSIX scheduler policy (-1 = creator default).

Definition at line 169 of file thread.hxx.

References dawn::CThreadedObject::SThreadConfig::scheduler.

◆ setThreadStackSize()

void dawn::CThreadedObject::setThreadStackSize ( size_t  stackSize)
inline

Configure worker thread stack size.

Parameters
stackSizeRequested stack size in bytes (0 = OS default).

Definition at line 129 of file thread.hxx.

References dawn::CThreadedObject::SThreadConfig::stackSize.

◆ startWorkerThread()

template<typename Func >
int dawn::CThreadedObject::startWorkerThread ( Func &&  func)
inlineprotected

Start the worker thread with a given function.

Parameters
funcCallable object to execute in thread.
Returns
OK on success, negative error code on failure.

Definition at line 246 of file thread.hxx.

References setThreadFunc(), and threadStart().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ stopWorkerThread()

int dawn::CThreadedObject::stopWorkerThread ( )
inlineprotected

Stop the worker thread.

Returns
OK on success, negative error code on failure.

Definition at line 258 of file thread.hxx.

References threadStop().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ threadStart()

int CThreadedObject::threadStart ( )

Start the worker thread.

Returns
OK on success, negative error code on failure.

Definition at line 166 of file thread.cxx.

Here is the caller graph for this function:

◆ threadStop()

int CThreadedObject::threadStop ( )

Stop the worker thread.

Returns
OK on success, negative error code on failure.

Definition at line 240 of file thread.cxx.

Here is the caller graph for this function:

◆ workerThread() [1/2]

CThreadedObject & dawn::CThreadedObject::workerThread ( )
inlineprotected

Get a reference to this thread controller.

Returns
Reference to this object.

Definition at line 280 of file thread.hxx.

◆ workerThread() [2/2]

const CThreadedObject & dawn::CThreadedObject::workerThread ( ) const
inlineprotected

Get a const reference to this thread controller.

Returns
Const reference to this object.

Definition at line 291 of file thread.hxx.

◆ workerThreadRunning()

bool dawn::CThreadedObject::workerThreadRunning ( ) const
inlineprotected

Check if the worker thread is running.

Returns
True if thread is running, false otherwise.

Definition at line 269 of file thread.hxx.

References isRunning().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ THREAD_PRIORITY_DEFAULT

int dawn::CThreadedObject::THREAD_PRIORITY_DEFAULT = 0
static

Default thread priority behavior.

Value 0 keeps the creator thread's default priority.

Definition at line 40 of file thread.hxx.

◆ THREAD_SCHEDULER_DEFAULT

int dawn::CThreadedObject::THREAD_SCHEDULER_DEFAULT = -1
static

Default scheduler behavior.

Value -1 keeps the creator thread's current scheduling policy.

Definition at line 48 of file thread.hxx.


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