From b5f13537ac7779bf7899d13cae738175c293d832 Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Mon, 29 Jul 2013 12:01:52 -0700 Subject: [PATCH] Add initiallySignaled parameter to WaitableEvent --- .../beast/modules/beast_core/native/beast_posix_SharedCode.h | 5 ++++- .../beast/modules/beast_core/native/beast_win32_Threads.cpp | 4 +++- .../beast/modules/beast_core/threads/beast_WaitableEvent.h | 5 ++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Subtrees/beast/modules/beast_core/native/beast_posix_SharedCode.h b/Subtrees/beast/modules/beast_core/native/beast_posix_SharedCode.h index 222490176..fd9d28b97 100644 --- a/Subtrees/beast/modules/beast_core/native/beast_posix_SharedCode.h +++ b/Subtrees/beast/modules/beast_core/native/beast_posix_SharedCode.h @@ -54,7 +54,7 @@ void CriticalSection::exit() const noexcept //============================================================================== -WaitableEvent::WaitableEvent (const bool useManualReset) noexcept +WaitableEvent::WaitableEvent (const bool useManualReset, bool initiallySignaled) noexcept : triggered (false), manualReset (useManualReset) { pthread_cond_init (&condition, 0); @@ -65,6 +65,9 @@ WaitableEvent::WaitableEvent (const bool useManualReset) noexcept pthread_mutexattr_setprotocol (&atts, PTHREAD_PRIO_INHERIT); #endif pthread_mutex_init (&mutex, &atts); + + if (initiallySignaled) + signal (); } WaitableEvent::~WaitableEvent() noexcept diff --git a/Subtrees/beast/modules/beast_core/native/beast_win32_Threads.cpp b/Subtrees/beast/modules/beast_core/native/beast_win32_Threads.cpp index 6c9f455a7..52438b5e8 100644 --- a/Subtrees/beast/modules/beast_core/native/beast_win32_Threads.cpp +++ b/Subtrees/beast/modules/beast_core/native/beast_win32_Threads.cpp @@ -80,9 +80,11 @@ void CriticalSection::exit() const noexcept } //============================================================================== -WaitableEvent::WaitableEvent (const bool manualReset) noexcept +WaitableEvent::WaitableEvent (const bool manualReset, bool initiallySignaled) noexcept : internal (CreateEvent (0, manualReset ? TRUE : FALSE, FALSE, 0)) { + if (initiallySignaled) + signal (); } WaitableEvent::~WaitableEvent() noexcept diff --git a/Subtrees/beast/modules/beast_core/threads/beast_WaitableEvent.h b/Subtrees/beast/modules/beast_core/threads/beast_WaitableEvent.h index 1a01d7e5c..22e610481 100644 --- a/Subtrees/beast/modules/beast_core/threads/beast_WaitableEvent.h +++ b/Subtrees/beast/modules/beast_core/threads/beast_WaitableEvent.h @@ -44,8 +44,11 @@ public: @param manualReset If this is false, the event will be reset automatically when the wait() method is called. If manualReset is true, then once the event is signalled, the only way to reset it will be by calling the reset() method. + + @param initiallySignaled If this is true then the event will be signaled when + the constructor returns. */ - explicit WaitableEvent (bool manualReset = false) noexcept; + explicit WaitableEvent (bool manualReset = false, bool initiallySignaled = false) noexcept; /** Destructor.