CppCommon  1.0.4.1
C++ Common Library
Public Member Functions | List of all members
CppCommon::EventAutoReset Class Reference

Auto-reset event synchronization primitive. More...

#include <event_auto_reset.h>

Public Member Functions

 EventAutoReset (bool signaled=false)
 Default class constructor. More...
 
 EventAutoReset (const EventAutoReset &)=delete
 
 EventAutoReset (EventAutoReset &&event)=delete
 
 ~EventAutoReset ()
 
EventAutoResetoperator= (const EventAutoReset &)=delete
 
EventAutoResetoperator= (EventAutoReset &&event)=delete
 
void Signal ()
 Signal one of waiting thread about event occurred. More...
 
bool TryWait ()
 Try to wait the event without block. More...
 
bool TryWaitFor (const Timespan &timespan)
 Try to wait the event for the given timespan. More...
 
bool TryWaitUntil (const UtcTimestamp &timestamp)
 Try to wait the event until the given timestamp. More...
 
void Wait ()
 Try to wait the event with block. More...
 

Detailed Description

Auto-reset event synchronization primitive.

Auto-reset event synchronization primitive allows multiple threads to wait for some event occurred and signal only one thread at the time. Other thread will wait for the next event signalization. The order of thread signalization by auto-reset event is not guaranteed.

Thread-safe.

https://en.wikipedia.org/wiki/Event_(synchronization_primitive)

Examples
threads_event_auto_reset.cpp.

Definition at line 28 of file event_auto_reset.h.

Constructor & Destructor Documentation

◆ EventAutoReset() [1/3]

CppCommon::EventAutoReset::EventAutoReset ( bool  signaled = false)
explicit

Default class constructor.

Parameters
signaled- Signaled event initial state (default is false)

Definition at line 170 of file event_auto_reset.cpp.

◆ EventAutoReset() [2/3]

CppCommon::EventAutoReset::EventAutoReset ( const EventAutoReset )
delete

◆ EventAutoReset() [3/3]

CppCommon::EventAutoReset::EventAutoReset ( EventAutoReset &&  event)
delete

◆ ~EventAutoReset()

CppCommon::EventAutoReset::~EventAutoReset ( )

Definition at line 181 of file event_auto_reset.cpp.

Member Function Documentation

◆ operator=() [1/2]

EventAutoReset& CppCommon::EventAutoReset::operator= ( const EventAutoReset )
delete

◆ operator=() [2/2]

EventAutoReset& CppCommon::EventAutoReset::operator= ( EventAutoReset &&  event)
delete

◆ Signal()

void CppCommon::EventAutoReset::Signal ( )

Signal one of waiting thread about event occurred.

If some threads are waiting for the event one will be chosen, signaled and continued. The order of thread signalization by auto-reset event is not guaranteed.

Will not block.

Definition at line 187 of file event_auto_reset.cpp.

◆ TryWait()

bool CppCommon::EventAutoReset::TryWait ( )

Try to wait the event without block.

Will not block.

Returns
'true' if the event was occurred before and no other threads were signaled, 'false' if the event was not occurred before

Definition at line 189 of file event_auto_reset.cpp.

◆ TryWaitFor()

bool CppCommon::EventAutoReset::TryWaitFor ( const Timespan timespan)

Try to wait the event for the given timespan.

Will block for the given timespan in the worst case.

Parameters
timespan- Timespan to wait for the event
Returns
'true' if the event was occurred, 'false' if the event was not occurred

Definition at line 190 of file event_auto_reset.cpp.

◆ TryWaitUntil()

bool CppCommon::EventAutoReset::TryWaitUntil ( const UtcTimestamp timestamp)
inline

Try to wait the event until the given timestamp.

Will block until the given timestamp in the worst case.

Parameters
timestamp- Timestamp to stop wait for the event
Returns
'true' if the event was occurred, 'false' if the event was not occurred

Definition at line 75 of file event_auto_reset.h.

◆ Wait()

void CppCommon::EventAutoReset::Wait ( )

Try to wait the event with block.

Will block.

Definition at line 192 of file event_auto_reset.cpp.


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