X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;ds=sidebyside;f=src%2Fthreading%2Fevent.h;h=ac6bd5129c4f7e64c59fb94d4fbb60d6fbadc241;hb=1f39948bc3341af99a1a2dfc39e4b4164ab56f4c;hp=0105630e5dbaf897965eb308bd4d80ee5153bb32;hpb=e4bff8be94c0db4f94e63ad448d0eeb869ccdbbd;p=dragonfireclient.git diff --git a/src/threading/event.h b/src/threading/event.h index 0105630e5..ac6bd5129 100644 --- a/src/threading/event.h +++ b/src/threading/event.h @@ -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 -#else - #include "threading/semaphore.h" -#endif - - -class Event { +#pragma once + +#include + +/** 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 -