|
Core Library
1.7.0.0
Library containing core utilities and tools for threading, networking, logging, INI and CSV file management etc.
|
Class defining a thread synchronisation event. More...
#include <SyncEvent.h>
Public Member Functions | |
| SyncEvent ()=default | |
| Default constructor. More... | |
| SyncEvent (eNotifyType notifyCondition, eResetCondition resetCondition, eIntialCondition initialCondition) | |
| Intialising constructor. More... | |
| ~SyncEvent ()=default | |
| Destructor. | |
| SyncEvent (const SyncEvent &)=delete | |
| Copy constructor - disabled. | |
| SyncEvent & | operator= (const SyncEvent &)=delete |
| Copy assignment operator - disabled. | |
| SyncEvent (SyncEvent &&)=delete | |
| Move constructor - disabled. | |
| SyncEvent & | operator= (SyncEvent &&)=delete |
| Move assignment operator - disabled. | |
| void | Wait () |
| Wait for event. More... | |
| bool | WaitForTime (size_t milliseconds) |
| Wait for event for a period of time. More... | |
| void | Signal () |
| Signal event. More... | |
| void | Reset () |
| Reset event.reset_condition. More... | |
Private Attributes | |
| std::mutex | m_signalMutex |
| Mutex to lock access to members. | |
| std::condition_variable | m_signalCondVar |
| Condition vairable to perform the waiting and signalling. | |
| bool | m_signalAllThreads {false} |
| Signal type flag. | |
| bool | m_autoReset {true} |
| Auto-reset flag. | |
| bool | m_signalFlag {false} |
| Signal flag. | |
Class defining a thread synchronisation event.
This class implemented a thread syncronisation event that is built using a mutex and a condition variable it makes for a neater implementation than using these types of object as is.
|
default |
Default constructor.
Create the SyncEvent in auto-reset mode, signaling one thread at a time and initially in a not signalled state.
| core_lib::threads::SyncEvent::SyncEvent | ( | eNotifyType | notifyCondition, |
| eResetCondition | resetCondition, | ||
| eIntialCondition | initialCondition | ||
| ) |
Intialising constructor.
| [in] | notifyCondition | - Notify type. |
| [in] | resetCondition | - Reset condition. |
| [in] | initialCondition | - Initial condition. |
Create the SyncEvent setting whether auto- or manual reset is to be used. Also setting whether when signalled it notifies all waiting threads or just one of them. Can also set the initial condition as signalled or not signalled.
If notifyCondition == eNotifyType::signalAllThreads then eResetCondition == eResetCondition::manualReset. This is because before you resue the event for signalling you must make sure all the signalled threads have finished their task(s) before the SyncEvent object is reset manually.
| void core_lib::threads::SyncEvent::Reset | ( | ) |
Reset event.reset_condition.
Use this function when SYncEvent created in maunal reset mode. Call to reset the signalled state of the event. This should not be called while athread is blocked on a call to Wait or WaitForTime. This should be called after the event has been signalled and Wait or WaitFor Time has returned and before calling Wait or WaitForTime again.
| void core_lib::threads::SyncEvent::Signal | ( | ) |
Signal event.
Call this function to signal the underlying condition variable. If a thread is blocked on a call to Wait or WaitForTime then the waiting function will unblock and return.
| void core_lib::threads::SyncEvent::Wait | ( | ) |
Wait for event.
Blocking function that waits until underlying condition variable is signalled at which point this function returns.
| bool core_lib::threads::SyncEvent::WaitForTime | ( | size_t | milliseconds | ) |
Wait for event for a period of time.
| [in] | milliseconds | - Number of milliseconds to wait. |
Blocking function that waits until underlying condition variable is signalled at which point this function returns or if not signalled this function returns after a defined number of milliseconds.