|
TcpLib
|
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 | STATUS { eAT_THE_START , eWORKING , ePAUSING , eENDING , eCOMPLETED } |
| enum | ORDER { eUNDEFINED , eDO_WORK , eEXIT } |
Public Member Functions | |
| RepeatingThread () | |
| virtual | ~RepeatingThread () |
| virtual int | start () |
| virtual void | cancel () |
| bool | testCancel () |
| RepeatingThread::STATUS | status () const |
| bool | isInExclusiveAccess () const |
| void | setExclusiveAccess () |
| void | unsetExclusiveAccess () |
| int | getBreakCounter () |
| virtual void | takeABreak () |
| virtual void | finishBreak () |
| void | waitForInput () |
| void | signalInput () |
Protected Member Functions | |
| void | threadWork () |
| void | setStatus (STATUS eStatus) |
| STATUS | getStatus () |
| void | toOrder (ORDER eOrder) |
| ORDER | getOrder () |
| virtual void | work ()=0 |
Private Member Functions | |
| RepeatingThread (const RepeatingThread &) | |
| RepeatingThread & | operator= (const RepeatingThread &) |
Private Attributes | |
| STATUS | m_eStatus |
| ORDER | m_eOrder |
| std::thread * | m_pThread |
| CriticalSection | m_ExclusiveAccessSection |
| std::mutex | m_WaitMutex |
| std::condition_variable | m_InputCondVar |
| std::mutex | m_BreakMutex |
| std::condition_variable | m_BreakCondVar |
| int | m_iBreakCounter |
| int | m_iDataReady |
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 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 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.
|
private |
Mutex to wait for input.