]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/threading/event.h
Fix BSD iconv declaration
[dragonfireclient.git] / src / threading / event.h
index 0105630e5dbaf897965eb308bd4d80ee5153bb32..ac6bd5129c4f7e64c59fb94d4fbb60d6fbadc241 100644 (file)
@@ -23,35 +23,24 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 DEALINGS IN THE SOFTWARE.
 */
 
-#ifndef THREADING_EVENT_H
-#define THREADING_EVENT_H
-
-#ifdef _WIN32
-       #include <windows.h>
-#else
-       #include "threading/semaphore.h"
-#endif
-
-
-class Event {
+#pragma once
+
+#include <condition_variable>
+
+/** A syncronization primitive that will wake up one waiting thread when signaled.
+ * Calling @c signal() multiple times before a waiting thread has had a chance
+ * to notice the signal will wake only one thread.  Additionally, if no threads
+ * are waiting on the event when it is signaled, the next call to @c wait()
+ * will return (almost) immediately.
+ */
+class Event
+{
 public:
-#ifdef _WIN32
-       Event() { event = CreateEvent(NULL, false, false, NULL); }
-       ~Event() { CloseHandle(event); }
-       void wait() { WaitForSingleObject(event, INFINITE); }
-       void signal() { SetEvent(event); }
-#else
-       void wait() { sem.wait(); }
-       void signal() { sem.post(); }
-#endif
+       void wait();
+       void signal();
 
 private:
-#ifdef _WIN32
-       HANDLE event;
-#else
-       Semaphore sem;
-#endif
+       std::condition_variable cv;
+       std::mutex mutex;
+       bool notified = false;
 };
-
-#endif
-