DynExp
Highly flexible laboratory automation for dynamically changing experiments.
Util::OneToOneNotifier Class Reference

Helper class to communicate flags between different threads based on a condition variable and a mutex. Two threads make use of the same instance of this class. One of the thread awaits a flag to be set by the other thread. More...

+ Inheritance diagram for Util::OneToOneNotifier:

Public Member Functions

 OneToOneNotifier ()
 
 ~OneToOneNotifier ()
 
bool Wait (const std::chrono::milliseconds Timeout=std::chrono::milliseconds(0))
 Makes current thread wait until it is notified or until given timeout duration is exceeded. Destructor might be called while Wait() is waiting (the waiting thread will be notified then). Wait() must not be called (of course) while destructor is running. More...
 
void Notify ()
 Set notification to stop waiting (sets EventOccurred to true). More...
 
void Ignore ()
 Ignore last notification (sets EventOccurred to false). More...
 
- Public Member Functions inherited from Util::INonCopyable
 INonCopyable (const INonCopyable &)=delete
 
INonCopyableoperator= (const INonCopyable &)=delete
 

Private Attributes

bool EventOccurred
 
bool SomeoneIsWaiting
 
std::atomic< bool > MutexCanBeDestroyed
 
std::mutex Mutex
 
std::condition_variable ConditionVariable
 

Additional Inherited Members

- Protected Member Functions inherited from Util::INonCopyable
constexpr INonCopyable ()=default
 
 ~INonCopyable ()=default
 

Detailed Description

Helper class to communicate flags between different threads based on a condition variable and a mutex. Two threads make use of the same instance of this class. One of the thread awaits a flag to be set by the other thread.

Definition at line 264 of file Util.h.

Constructor & Destructor Documentation

◆ OneToOneNotifier()

Util::OneToOneNotifier::OneToOneNotifier ( )
inline

Definition at line 267 of file Util.h.

◆ ~OneToOneNotifier()

Util::OneToOneNotifier::~OneToOneNotifier ( )

Definition at line 30 of file Util.cpp.

Member Function Documentation

◆ Ignore()

void Util::OneToOneNotifier::Ignore ( )

Ignore last notification (sets EventOccurred to false).

Definition at line 79 of file Util.cpp.

◆ Notify()

void Util::OneToOneNotifier::Notify ( )

Set notification to stop waiting (sets EventOccurred to true).

Definition at line 69 of file Util.cpp.

◆ Wait()

bool Util::OneToOneNotifier::Wait ( const std::chrono::milliseconds  Timeout = std::chrono::milliseconds(0))

Makes current thread wait until it is notified or until given timeout duration is exceeded. Destructor might be called while Wait() is waiting (the waiting thread will be notified then). Wait() must not be called (of course) while destructor is running.

Parameters
TimeoutTime to wait for a notification. 0 ms means that the functions waits without timing out ever.
Returns
Returns true if the function returned due to an exceeded timeout duration. Returns false if the function returned due to the OneToOneNotifier having been notified.
Exceptions
InvalidCallExceptionis thrown if a thread is already waiting for this notifier.

Definition at line 39 of file Util.cpp.

Member Data Documentation

◆ ConditionVariable

std::condition_variable Util::OneToOneNotifier::ConditionVariable
private

Definition at line 290 of file Util.h.

◆ EventOccurred

bool Util::OneToOneNotifier::EventOccurred
private

Definition at line 285 of file Util.h.

◆ Mutex

std::mutex Util::OneToOneNotifier::Mutex
private

Definition at line 289 of file Util.h.

◆ MutexCanBeDestroyed

std::atomic<bool> Util::OneToOneNotifier::MutexCanBeDestroyed
private

Definition at line 287 of file Util.h.

◆ SomeoneIsWaiting

bool Util::OneToOneNotifier::SomeoneIsWaiting
private

Definition at line 286 of file Util.h.


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