2012-06-14 09:06:06 -04:00
|
|
|
|
2012-09-23 17:23:33 -04:00
|
|
|
// Event.h
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2014-10-23 05:20:25 -04:00
|
|
|
// Interfaces to the cEvent object representing a synchronization primitive that can be waited-for
|
|
|
|
// Implemented using C++11 condition variable and mutex
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#pragma once
|
2014-10-23 05:20:25 -04:00
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class cEvent
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
cEvent(void);
|
|
|
|
|
2014-10-23 05:20:25 -04:00
|
|
|
/** Waits until the event has been set.
|
|
|
|
If the event has been set before it has been waited for, Wait() returns immediately. */
|
2012-06-14 09:06:06 -04:00
|
|
|
void Wait(void);
|
2014-10-23 05:20:25 -04:00
|
|
|
|
|
|
|
/** Sets the event - releases one thread that has been waiting in Wait().
|
|
|
|
If there was no thread waiting, the next call to Wait() will not block. */
|
2015-06-22 16:27:13 -04:00
|
|
|
void Set(void);
|
|
|
|
|
|
|
|
/** Sets the event - releases all threads that have been waiting in Wait().
|
|
|
|
If there was no thread waiting, the next call to Wait() will not block. */
|
|
|
|
void SetAll(void);
|
2014-10-05 13:04:30 -04:00
|
|
|
|
|
|
|
/** Waits for the event until either it is signalled, or the (relative) timeout is passed.
|
|
|
|
Returns true if the event was signalled, false if the timeout was hit or there was an error. */
|
2014-12-07 15:37:47 -05:00
|
|
|
bool Wait(unsigned a_TimeoutMSec);
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
private:
|
|
|
|
|
2014-10-23 05:20:25 -04:00
|
|
|
/** Used for checking for spurious wakeups. */
|
2015-08-26 18:02:45 -04:00
|
|
|
bool m_ShouldContinue;
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2015-06-22 16:27:13 -04:00
|
|
|
/** Mutex protecting m_ShouldContinue from multithreaded access. */
|
2014-10-23 05:20:25 -04:00
|
|
|
std::mutex m_Mutex;
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2014-10-23 05:20:25 -04:00
|
|
|
/** The condition variable used as the Event. */
|
|
|
|
std::condition_variable m_CondVar;
|
|
|
|
} ;
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|