GlobalObjects
|
Base class for a thread that executes its work endlessly until aborted. More...
#include <EuRepeatingThread.h>
Public Types | |
enum | EuTHREADERROR { EuTHREAD_ERR_NO_THREAD = -10301 , EuTHREAD_ERR_THREAD_ALREADY_WORKING = -10302 , EuTHREAD_ERR_THREAD_BREAK_COUNT_LESS_THAN_ZERO = -10303 , EuTHREAD_ERR_UNKNOWN = -10400 } |
Error range = -10301 to -10400 More... | |
enum | ORDER { eUNDEFINED , eDO_WORK , eEXIT } |
enum | STATUS { eAT_THE_START , eWORKING , ePAUSING , eENDING , eCOMPLETED } |
Public Member Functions | |
RepeatingThread () | |
virtual | ~RepeatingThread () |
virtual void | cancel () |
virtual void | finishBreak () |
int | getBreakCounter () |
bool | isInExclusiveAccess () const |
void | setExclusiveAccess () |
void | signalInput () |
virtual int | start () |
RepeatingThread::STATUS | status () const |
virtual void | takeABreak () |
bool | testCancel () |
void | unsetExclusiveAccess () |
void | waitForInput () |
Public Attributes | |
std::string | m_strDebugInfo |
Protected Member Functions | |
ORDER | getOrder () |
STATUS | getStatus () |
void | setStatus (STATUS eStatus) |
void | threadWork () |
void | toOrder (ORDER eOrder) |
virtual void | work ()=0 |
Private Member Functions | |
RepeatingThread (const RepeatingThread &) | |
RepeatingThread & | operator= (const RepeatingThread &) |
Private Attributes | |
std::condition_variable | m_BreakCondVar |
std::mutex | m_BreakMutex |
ORDER | m_eOrder |
STATUS | m_eStatus |
CriticalSection | m_ExclusiveAccessSection |
int | m_iBreakCounter |
int | m_iDataReady |
std::condition_variable | m_InputCondVar |
std::thread * | m_pThread |
std::mutex | m_WaitMutex |
Base class for a thread that executes its work endlessly until aborted.
In subclasses, only the virtual method RepeatingThread::work() must be overwritten.
Error range = -10301 to -10400
A RepeatingThread can be given instructions after the start.
Enumerator | |
---|---|
eUNDEFINED | Undefined. |
eDO_WORK | Thread should work. |
eEXIT | Thread should end. |
eut::RepeatingThread::RepeatingThread | ( | ) |
Standard constructor.
|
virtual |
|
private |
The copy constructor is not available.
|
virtual |
Terminates the thread.
Reimplemented in glo::ClientThread, glo::CommunicaterThread, glo::LocalThread, glo::Server, glo::WatchNotifyManager, tcp::Client, tcp::ClientReceiver, tcp::Server, tcp::ServerAcceptReceiver, tcp::ServerReceiver, and tcp::Transmitter.
|
virtual |
Ends the working pause. Must have been initiated by takeABreak().
Reimplemented in tcp::ReceiverTransmitter.
int eut::RepeatingThread::getBreakCounter | ( | ) |
Returns the pause counter.
|
protected |
Returns the last transferred instruction.
|
protected |
Returns the current status.
bool eut::RepeatingThread::isInExclusiveAccess | ( | ) | const |
Is the thread in an exclusive area?
|
private |
Assignment operator is not available.
void eut::RepeatingThread::setExclusiveAccess | ( | ) |
Initiates a CriticalSection. Must be canceled using unsetExclusiveAccess ().
|
protected |
Set the status.
[in] | eStatus | The status to be set. |
void eut::RepeatingThread::signalInput | ( | ) |
Ends the wait without activity initiated by waitForInput().
|
virtual |
RepeatingThread::STATUS eut::RepeatingThread::status | ( | ) | const |
Returns the status of the thread.
|
virtual |
Initiates a pause of the thread to interrupt the processing. Must be ended again with finishBreak().
Reimplemented in tcp::ReceiverTransmitter.
bool eut::RepeatingThread::testCancel | ( | ) |
Returns true when thread has ended.
|
protected |
This method, executed by the thread, calls the method work() in a loop.
|
protected |
Accepts the transferred instruction.
[in] | eOrder | The statement to be set. |
void eut::RepeatingThread::unsetExclusiveAccess | ( | ) |
Cancels an initiated CriticalSection if set by setExclusiveAccess()
void eut::RepeatingThread::waitForInput | ( | ) |
Lets the thread wait at a defined position without activity. Must be terminated again by signalInput().
|
protectedpure virtual |
This method is executed by the thread and must be overwritten in subclasses.
Implemented in glo::CommunicaterThread, glo::Communicator, glo::Manager, glo::WatchNotifyManager, tcp::Client, tcp::ClientReceiver, tcp::Server, tcp::ServerAcceptReceiver, tcp::ServerReceiver, and tcp::Transmitter.
|
private |
Condition_variable to pause
|
private |
Mutex to pause.
|
private |
A thread can be given a command which is set here.
|
private |
The working status.
|
private |
Is required to define access protected areas by RepeatingThread::setExclusiveAccess() or RepeatingThread::unsetExclusiveAccess().
|
private |
If a RepeatingThread is to pause, this counter is incremented. If the thread should wake up again, this counter is decremented. At 0 the thread is woken up again.
This enables a nested sleep and wake up.
|
private |
To avoid "lost wakeup" and "spurious wakeups" this variable is necessary.
Found in: https://www.modernescpp.com/index.php/c-core-guidelines-be-aware-of-the-traps-of-condition-variables
|
private |
Condition_variable to wait for input.
|
private |
The 'real' thread.
std::string eut::RepeatingThread::m_strDebugInfo |
Here you can write something in for DEBUG purposes.
|
private |
Mutex to wait for input.