summaryrefslogtreecommitdiffstats
path: root/src/OSSupport/Event.h
diff options
context:
space:
mode:
authorHowaner <franzi.moos@googlemail.com>2014-12-13 20:10:23 +0100
committerHowaner <franzi.moos@googlemail.com>2014-12-13 20:10:23 +0100
commita595a4a842123f10a4b27ae082794bad0250a307 (patch)
treeb0f50e06e6f7a55a8d5a18cfb37a53234f527236 /src/OSSupport/Event.h
parentAdded cocoa pod. (diff)
parentMerge pull request #1663 from mc-server/APIDumpSize (diff)
downloadcuberite-a595a4a842123f10a4b27ae082794bad0250a307.tar
cuberite-a595a4a842123f10a4b27ae082794bad0250a307.tar.gz
cuberite-a595a4a842123f10a4b27ae082794bad0250a307.tar.bz2
cuberite-a595a4a842123f10a4b27ae082794bad0250a307.tar.lz
cuberite-a595a4a842123f10a4b27ae082794bad0250a307.tar.xz
cuberite-a595a4a842123f10a4b27ae082794bad0250a307.tar.zst
cuberite-a595a4a842123f10a4b27ae082794bad0250a307.zip
Diffstat (limited to 'src/OSSupport/Event.h')
-rw-r--r--src/OSSupport/Event.h35
1 files changed, 18 insertions, 17 deletions
diff --git a/src/OSSupport/Event.h b/src/OSSupport/Event.h
index e2fa65a05..572388a3f 100644
--- a/src/OSSupport/Event.h
+++ b/src/OSSupport/Event.h
@@ -1,16 +1,17 @@
// Event.h
-// Interfaces to the cEvent object representing an OS-specific synchronization primitive that can be waited-for
-// Implemented as an Event on Win and as a 1-semaphore on *nix
+// Interfaces to the cEvent object representing a synchronization primitive that can be waited-for
+// Implemented using C++11 condition variable and mutex
#pragma once
-#ifndef CEVENT_H_INCLUDED
-#define CEVENT_H_INCLUDED
+
+#include <mutex>
+#include <condition_variable>
@@ -20,31 +21,31 @@ class cEvent
{
public:
cEvent(void);
- ~cEvent();
+ /** Waits until the event has been set.
+ If the event has been set before it has been waited for, Wait() returns immediately. */
void Wait(void);
+
+ /** 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. */
void Set (void);
/** 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. */
- bool Wait(int a_TimeoutMSec);
+ bool Wait(unsigned a_TimeoutMSec);
private:
- #ifdef _WIN32
- HANDLE m_Event;
- #else
- sem_t * m_Event;
- bool m_bIsNamed;
- #endif
-} ;
-
-
-
+ /** Used for checking for spurious wakeups. */
+ bool m_ShouldWait;
+ /** Mutex protecting m_ShouldWait from multithreaded access. */
+ std::mutex m_Mutex;
+ /** The condition variable used as the Event. */
+ std::condition_variable m_CondVar;
+} ;
-#endif // CEVENT_H_INCLUDED