Ocean
Ocean::Worker::WorkerThread Class Reference

This class implements a thread with an explicit external thread function. More...

Inheritance diagram for Ocean::Worker::WorkerThread:

Public Types

enum  WorkerState { WS_UNKNOWN_RESULT , WS_POSITIVE_RESULT , WS_NEGATIVE_RESULT }
 Definition of different worker thread states. More...
 

Public Member Functions

 WorkerThread (const unsigned int workerSeedValue, const unsigned int workerThreadId)
 Creates a new worker thread object. More...
 
virtual ~WorkerThread ()
 Destructs a worker thread object. More...
 
unsigned int id ()
 Returns the id of this worker thread. More...
 
bool start (Signal &signal)
 Starts the worker thread. More...
 
void setThreadFunction (const Function &function)
 Sets a new thread function which will be executed immediately using the internal thread. More...
 
void setThreadFunction (Function &&function)
 Sets/moves a new thread function which will be executed immediately using the internal thread. More...
 
void setThreadFunction (const AbortableFunction &abortableFunction, const unsigned int abortIndex)
 Sets a new thread function which will be executed immediately using the internal thread. More...
 
void setThreadFunction (AbortableFunction &&abortableFunction, const unsigned int abortIndex)
 Sets/moves a new thread function which will be executed immediately using the internal thread. More...
 
WorkerState state () const
 Returns the current worker thread state. More...
 

Private Member Functions

virtual void threadRun ()
 This thread function has to be overloaded by derived classes. More...
 

Private Attributes

Function function_
 Function using the internal thread to execute. More...
 
AbortableFunction abortableFunction_
 Abortable function using the internal thread to execute. More...
 
Signal internalSignal_
 Internal signal handling the internal thread execution. More...
 
SignalexternalSignal_ = nullptr
 External signal determining the termination of the thread function. More...
 
unsigned int id_ = (unsigned int)(-1)
 Id of the worker thread. More...
 
unsigned int abortIndex_ = (unsigned int)(-1)
 Index the abort parameter for abortable thread functions. More...
 
WorkerState workerState_
 Worker thread result. More...
 

Additional Inherited Members

- Protected Types inherited from Ocean::Thread
typedef std::pair< pthread_t, bool > TimedJoinPair
 Definition of a pair holding a thread id and a boolean state. More...
 
enum  ThreadPriority {
  PRIORITY_IDLE , PRIORTY_BELOW_NORMAL , PRIORTY_NORMAL , PRIORTY_ABOVE_NORMAL ,
  PRIORTY_HIGH , PRIORTY_REALTIME
}
 Definition of different thread priority values. More...
 
- Protected Member Functions inherited from Ocean::Thread
 Thread (const Thread &thread)=delete
 Disabled copy constructor. More...
 
void createThread ()
 Creates the thread itself. More...
 
void destroyThread ()
 Destroys the thread itself. More...
 
void stopThreadExplicitly (const unsigned int timeout=5000u)
 Tries to stop the thread gracefully. More...
 
Threadoperator= (const Thread &thread)=delete
 The disabled assign operator. More...
 
 Thread (const std::string &name=std::string())
 Creates a new thread object. More...
 
 Thread (const unsigned int randomNumberSeedValue, const std::string &name=std::string())
 Creates a new thread object. More...
 
virtual ~Thread ()
 Destructs a thread object. More...
 
bool startThread ()
 Starts the thread. More...
 
void stopThread ()
 Informs the thread to stop. More...
 
bool terminateThread ()
 Terminates the thread. More...
 
bool joinThread (const unsigned int timeout=(unsigned int)(-1))
 Waits until this thread has been stopped. More...
 
bool shouldThreadStop () const
 Returns whether this thread should stop. More...
 
bool isThreadInvokedToStart () const
 Returns whether this thread has been invoked to start immediately. More...
 
bool isThreadActive () const
 Returns whether this thread is active. More...
 
- Static Protected Member Functions inherited from Ocean::Thread
static void sleep (unsigned int ms)
 Sleeps the calling thread for a given time. More...
 
static void giveUp ()
 Gives up the remaining thread time. More...
 
static ThreadId currentThreadId ()
 Returns the thread id of the current (calling) thread. More...
 
static ThreadPriority threadPriority ()
 Returns the priority of the current thread. More...
 
static bool setThreadPriority (const ThreadPriority priority)
 Sets the priority of the current thread. More...
 
template<typename TObject , typename TExpectedValue >
static bool waitForValue (TObject &object, const TExpectedValue &expectedValue, const double timeout=-1.0)
 Waits until an object/variable has an expected value. More...
 
template<typename TObject , typename TExpectedValue >
static bool waitForValue (TObject &object, const TExpectedValue &expectedValue, TemporaryScopedLock &temporaryScopedLock, const double timeout=-1.0)
 Waits until an object/variable has an expected value. More...
 
static int pthread_timedjoin_np (pthread_t thread, void **retval, const struct timespec *abstime)
 Implements a thread join function with timeout value. More...
 

Detailed Description

This class implements a thread with an explicit external thread function.


Member Enumeration Documentation

◆ WorkerState

Definition of different worker thread states.

Enumerator
WS_UNKNOWN_RESULT 

The worker thread is in a state with unknown result.

WS_POSITIVE_RESULT 

The worker thread is in a state with positive function result.

WS_NEGATIVE_RESULT 

The worker thread is in a state with negative function result.

Constructor & Destructor Documentation

◆ WorkerThread()

Ocean::Worker::WorkerThread::WorkerThread ( const unsigned int  workerSeedValue,
const unsigned int  workerThreadId 
)
explicit

Creates a new worker thread object.

Parameters
workerSeedValueWorker specific seed value e.g., for random number generators, each thread will work with an own seed value: threadSeedValue = workerSeedValue + workerThreadId
workerThreadIdId of the worker thread to distinguish between all threads owned by one worker

◆ ~WorkerThread()

virtual Ocean::Worker::WorkerThread::~WorkerThread ( )
virtual

Destructs a worker thread object.

Member Function Documentation

◆ id()

unsigned int Ocean::Worker::WorkerThread::id ( )
inline

Returns the id of this worker thread.

Returns
Worker thread id

◆ setThreadFunction() [1/4]

void Ocean::Worker::WorkerThread::setThreadFunction ( AbortableFunction &&  abortableFunction,
const unsigned int  abortIndex 
)
inline

Sets/moves a new thread function which will be executed immediately using the internal thread.

Parameters
abortableFunctionThread function able to be aborted during execution, will be moved
abortIndexIndex of the boolean abort parameter, which must be a pointer to a boolean parameter

◆ setThreadFunction() [2/4]

void Ocean::Worker::WorkerThread::setThreadFunction ( const AbortableFunction abortableFunction,
const unsigned int  abortIndex 
)
inline

Sets a new thread function which will be executed immediately using the internal thread.

Parameters
abortableFunctionThread function able to be aborted during execution
abortIndexIndex of the boolean abort parameter, which must be a pointer to a boolean parameter

◆ setThreadFunction() [3/4]

void Ocean::Worker::WorkerThread::setThreadFunction ( const Function function)
inline

Sets a new thread function which will be executed immediately using the internal thread.

Parameters
functionThread function to be set

◆ setThreadFunction() [4/4]

void Ocean::Worker::WorkerThread::setThreadFunction ( Function &&  function)
inline

Sets/moves a new thread function which will be executed immediately using the internal thread.

Parameters
functionThread function to be moved

◆ start()

bool Ocean::Worker::WorkerThread::start ( Signal signal)

Starts the worker thread.

Parameters
signalExtern worker signal pushed if this thread has finished
Returns
True, if succeeded

◆ state()

Worker::WorkerThread::WorkerState Ocean::Worker::WorkerThread::state ( ) const
inline

Returns the current worker thread state.

Returns
Worker state

◆ threadRun()

virtual void Ocean::Worker::WorkerThread::threadRun ( )
privatevirtual

This thread function has to be overloaded by derived classes.

See also
Thread::threadRun().

Implements Ocean::Thread.

Field Documentation

◆ abortableFunction_

AbortableFunction Ocean::Worker::WorkerThread::abortableFunction_
private

Abortable function using the internal thread to execute.

◆ abortIndex_

unsigned int Ocean::Worker::WorkerThread::abortIndex_ = (unsigned int)(-1)
private

Index the abort parameter for abortable thread functions.

◆ externalSignal_

Signal* Ocean::Worker::WorkerThread::externalSignal_ = nullptr
private

External signal determining the termination of the thread function.

◆ function_

Function Ocean::Worker::WorkerThread::function_
private

Function using the internal thread to execute.

◆ id_

unsigned int Ocean::Worker::WorkerThread::id_ = (unsigned int)(-1)
private

Id of the worker thread.

◆ internalSignal_

Signal Ocean::Worker::WorkerThread::internalSignal_
private

Internal signal handling the internal thread execution.

◆ workerState_

WorkerState Ocean::Worker::WorkerThread::workerState_
private

Worker thread result.


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