summaryrefslogtreecommitdiff
path: root/os_wrappers/Event.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'os_wrappers/Event.cpp')
-rwxr-xr-xos_wrappers/Event.cpp56
1 files changed, 56 insertions, 0 deletions
diff --git a/os_wrappers/Event.cpp b/os_wrappers/Event.cpp
new file mode 100755
index 0000000..0390735
--- /dev/null
+++ b/os_wrappers/Event.cpp
@@ -0,0 +1,56 @@
+/*
+ * Event.cpp
+ *
+ * Copyright (C) ST-Ericsson SA 2011
+ * Authors: Srimanta Panda <srimanta.panda@stericsson.com>,
+ * Ola Borgelin <ola.borgelin@stericsson.com>,
+ * Karin Hedlund <karin.hedlund@stericsson.com>,
+ * Markus Andersson <markus.m.andersson@stericsson.com> for ST-Ericsson.
+ * License terms: 3-clause BSD license
+ *
+ */
+
+/*
+ * @addtogroup OS Wrappers
+ * @{
+ */
+
+#include "Event.h"
+
+Event::Event()
+{
+#ifdef _WIN32
+ semaphore_ = CreateSemaphore(NULL, 0, 256, NULL);
+#else
+ sem_init(&semaphore_, 0, 0);
+#endif
+}
+
+Event::~Event()
+{
+#ifdef _WIN32
+ CloseHandle(semaphore_);
+#else
+ sem_destroy(&semaphore_);
+#endif
+}
+
+void Event::signal()
+{
+#ifdef _WIN32
+ ReleaseSemaphore(semaphore_, 1, NULL);
+#else
+ sem_post(&semaphore_);
+#endif
+}
+
+void Event::wait(unsigned long timeout __attribute__((unused)))
+{
+#ifdef _WIN32
+ WaitForSingleObject(semaphore_, timeout);
+#else
+ sem_wait(&semaphore_);
+#endif
+}
+
+/* @} */