Ocean
|
This class implements a thread with an explicit external thread function. More...
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... | |
Signal * | externalSignal_ = 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... | |
Thread & | operator= (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... | |
This class implements a thread with an explicit external thread function.
|
explicit |
Creates a new worker thread object.
workerSeedValue | Worker specific seed value e.g., for random number generators, each thread will work with an own seed value: threadSeedValue = workerSeedValue + workerThreadId |
workerThreadId | Id of the worker thread to distinguish between all threads owned by one worker |
|
virtual |
Destructs a worker thread object.
|
inline |
Returns the id of this worker thread.
|
inline |
Sets/moves a new thread function which will be executed immediately using the internal thread.
abortableFunction | Thread function able to be aborted during execution, will be moved |
abortIndex | Index of the boolean abort parameter, which must be a pointer to a boolean parameter |
|
inline |
Sets a new thread function which will be executed immediately using the internal thread.
abortableFunction | Thread function able to be aborted during execution |
abortIndex | Index of the boolean abort parameter, which must be a pointer to a boolean parameter |
|
inline |
Sets a new thread function which will be executed immediately using the internal thread.
function | Thread function to be set |
|
inline |
Sets/moves a new thread function which will be executed immediately using the internal thread.
function | Thread function to be moved |
bool Ocean::Worker::WorkerThread::start | ( | Signal & | signal | ) |
Starts the worker thread.
signal | Extern worker signal pushed if this thread has finished |
|
inline |
Returns the current worker thread state.
|
privatevirtual |
This thread function has to be overloaded by derived classes.
Implements Ocean::Thread.
|
private |
Abortable function using the internal thread to execute.
|
private |
Index the abort parameter for abortable thread functions.
|
private |
External signal determining the termination of the thread function.
|
private |
Function using the internal thread to execute.
|
private |
Id of the worker thread.
|
private |
Internal signal handling the internal thread execution.
|
private |
Worker thread result.