GlobalObjects
Loading...
Searching...
No Matches
EuEndlessPThread Class Reference

Base class for a thread that executes its work endlessly until aborted. More...

#include <EuEndlessPThread.h>

Inheritance diagram for EuEndlessPThread:

Public Types

enum  EuPTHREAD_ORDER { EuPTHREAD_WORK , EuPTHREAD_TAKE_A_BREAK , EuPTHREAD_END }
 
- Public Types inherited from EuAPThread
enum  EuPTHREAD_STATUS { EuPTHREAD_AT_THE_START , EuPTHREAD_WORKING , EuPTHREAD_PAUSING , EuPTHREAD_FINISHED }
 

Public Member Functions

 EuEndlessPThread ()
 
virtual ~EuEndlessPThread ()
 
virtual int cancel ()
 
virtual int finishBreak ()
 
int getBreakCounter ()
 
void setExclusiveAccess ()
 
void signalInput ()
 
virtual int start ()
 
virtual int takeABreak ()
 
void unsetExclusiveAccess ()
 
void waitForInput ()
 
- Public Member Functions inherited from EuAPThread
 EuAPThread ()
 
virtual ~EuAPThread ()
 
virtual int join ()
 
EuAPThread::EuPTHREAD_STATUS status () const
 
void testCancel ()
 

Protected Member Functions

void takeABreakWait ()
 
- Protected Member Functions inherited from EuAPThread
virtual void cleanUp ()
 
virtual void work ()=0
 

Static Protected Member Functions

static void * threadWork (void *pParam)
 
- Static Protected Member Functions inherited from EuAPThread
static void _cleanUp (void *pParam)
 

Protected Attributes

bool m_bInExluzivAccess
 
pthread_cond_t m_BreakCond
 
EuPTHREAD_ORDER m_eThreadOrder
 
pthread_mutex_t m_ExclusiveAccessMutex
 
int m_iBreakCounter
 
sem_t m_Semaphore
 
- Protected Attributes inherited from EuAPThread
EuPTHREAD_STATUS m_eThreadStatus
 
std::string m_strDebugInfo
 
pthread_t m_Thread
 

Private Member Functions

 EuEndlessPThread (const EuEndlessPThread &)
 
EuEndlessPThreadoperator= (const EuEndlessPThread &)
 

Detailed Description

Base class for a thread that executes its work endlessly until aborted.

In subclasses, only the virtual method EuAPThread::work() must be overwritten.

Attention
The thread must be terminated after the start with cancel() before calling the destructor!
Note
Based on 32 bit POSIX threads.
Author
Helmut Jakoby

Member Enumeration Documentation

◆ EuPTHREAD_ORDER

Commands can be passed to a derived EuEndlessPThread after the start.

Enumerator
EuPTHREAD_WORK 

Thread should work.

EuPTHREAD_TAKE_A_BREAK 

Thread should skip working (not working, but also not aborting)

EuPTHREAD_END 

Thread should end.

Constructor & Destructor Documentation

◆ EuEndlessPThread() [1/2]

EuEndlessPThread::EuEndlessPThread ( )

Standard constructor.

◆ ~EuEndlessPThread()

virtual EuEndlessPThread::~EuEndlessPThread ( )
virtual

The destructor remove # m_ExclusiveAccessMutex, m_BreakCond and m_Semaphore from memory.
Destructor, see also the description of the superclasses.

Attention
The method cancel() must be called before the destructor! Since cancel() is virtual, it cannot be executed in dtor.
Exceptions
eut::ErrorNExceptionIf the thread is already started and not yet finished, an exception is thrown.

◆ EuEndlessPThread() [2/2]

EuEndlessPThread::EuEndlessPThread ( const EuEndlessPThread & )
private

The copy constructor is not available.

Member Function Documentation

◆ cancel()

virtual int EuEndlessPThread::cancel ( )
virtual

Terminates the thread.

Attention
Must be called before the destructor if started with start()!
Since cancel() virtual, this cannot be executed in dtor.
Returns
A return value < 0 indicates an error or info.
Attention
The thread must have been started with start().

Reimplemented from EuAPThread.

◆ finishBreak()

virtual int EuEndlessPThread::finishBreak ( )
virtual

Ends the processing pause ( if m_iBreakCounter == 0 ). Must have been initiated by takeABreak().

Returns
A return value < 0 indicates an error.

◆ getBreakCounter()

int EuEndlessPThread::getBreakCounter ( )

Return m_iBreakCounter.

◆ operator=()

EuEndlessPThread & EuEndlessPThread::operator= ( const EuEndlessPThread & )
private

The assignment operator is not available.

◆ setExclusiveAccess()

void EuEndlessPThread::setExclusiveAccess ( )

Set a lock on his mutex. Must be released with unsetExclusiveAccess().

◆ signalInput()

void EuEndlessPThread::signalInput ( )

Ends the wait without activity initiated by waitForInput().

◆ start()

virtual int EuEndlessPThread::start ( )
virtual

Starts the thread.

Returns
A return value < 0 indicates an error. E.g. if thread is already running.
Attention
The thread must be terminated after start() before the destructor with cancel().

Implements EuAPThread.

◆ takeABreak()

virtual int EuEndlessPThread::takeABreak ( )
virtual

Sets m_eThreadOrder to EuPTHREAD_TAKE_A_BREAK. This method can be used to skip or not execute the processing.
Must be terminated by finishBreak().

Returns
A return value < 0 indicates an error.

◆ takeABreakWait()

void EuEndlessPThread::takeABreakWait ( )
protected

Is needed in threadWork( void * pParam ) to pause.

◆ threadWork()

static void * EuEndlessPThread::threadWork ( void * pParam)
staticprotected

This method is needed in start().

Parameters
[in]pParamIn order for this static method to access the method EuAPThread::work(), a reference to the respective instance of an object of the EuEndlessPThread or subclass type is expected in pParam.
See also
EuAPThread::_cleanUp(void * pParam)

◆ unsetExclusiveAccess()

void EuEndlessPThread::unsetExclusiveAccess ( )

Releases a lock on its mutex when set by setExclusiveAccess().

◆ waitForInput()

void EuEndlessPThread::waitForInput ( )

Lets the thread wait at a defined position without activity. Must be terminated again by signalInput().

Member Data Documentation

◆ m_bInExluzivAccess

bool EuEndlessPThread::m_bInExluzivAccess
protected

To set a mutex this attribute is required.

◆ m_BreakCond

pthread_cond_t EuEndlessPThread::m_BreakCond
protected

This attribute is necessary to pause the thread.

◆ m_eThreadOrder

EuPTHREAD_ORDER EuEndlessPThread::m_eThreadOrder
protected

A thread can be given a command which is set here.

◆ m_ExclusiveAccessMutex

pthread_mutex_t EuEndlessPThread::m_ExclusiveAccessMutex
protected

This Thraed needs a mutex to protect local variables.

◆ m_iBreakCounter

int EuEndlessPThread::m_iBreakCounter
protected

If a EuEndlessPThread is to be paused, this counter is incremented; it is decremented again on wakeup. At 0, the thread is woken up again.

This enables a nested sleep and wake up.

◆ m_Semaphore

sem_t EuEndlessPThread::m_Semaphore
protected

Can be used to prevent the thread from idling. This is not the same as pausing, where the thread just skips processing.


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