diff options
author | Tiger Wang <ziwei.tiger@hotmail.co.uk> | 2015-08-27 00:02:45 +0200 |
---|---|---|
committer | Tiger Wang <ziwei.tiger@hotmail.co.uk> | 2015-08-27 00:02:45 +0200 |
commit | dfc0f2ae007e186c724b871c7df27f2bf43f76d6 (patch) | |
tree | 0d93c887cb9687ef01ea4fa153ea8e131775fd3b | |
parent | Merge pull request #2450 from nicodinh/patch-1 (diff) | |
download | cuberite-dfc0f2ae007e186c724b871c7df27f2bf43f76d6.tar cuberite-dfc0f2ae007e186c724b871c7df27f2bf43f76d6.tar.gz cuberite-dfc0f2ae007e186c724b871c7df27f2bf43f76d6.tar.bz2 cuberite-dfc0f2ae007e186c724b871c7df27f2bf43f76d6.tar.lz cuberite-dfc0f2ae007e186c724b871c7df27f2bf43f76d6.tar.xz cuberite-dfc0f2ae007e186c724b871c7df27f2bf43f76d6.tar.zst cuberite-dfc0f2ae007e186c724b871c7df27f2bf43f76d6.zip |
Diffstat (limited to '')
-rw-r--r-- | src/OSSupport/Event.cpp | 18 | ||||
-rw-r--r-- | src/OSSupport/Event.h | 3 |
2 files changed, 13 insertions, 8 deletions
diff --git a/src/OSSupport/Event.cpp b/src/OSSupport/Event.cpp index 4c2adea3c..be2803451 100644 --- a/src/OSSupport/Event.cpp +++ b/src/OSSupport/Event.cpp @@ -25,9 +25,9 @@ void cEvent::Wait(void) { { std::unique_lock<std::mutex> Lock(m_Mutex); - m_CondVar.wait(Lock, [this](){ return m_ShouldContinue.load(); }); + m_CondVar.wait(Lock, [this](){ return m_ShouldContinue; }); + m_ShouldContinue = false; } - m_ShouldContinue = false; } @@ -40,9 +40,9 @@ bool cEvent::Wait(unsigned a_TimeoutMSec) bool Result; { std::unique_lock<std::mutex> Lock(m_Mutex); // We assume that this lock is acquired without much delay - we are the only user of the mutex - Result = m_CondVar.wait_until(Lock, dst, [this](){ return m_ShouldContinue.load(); }); + Result = m_CondVar.wait_until(Lock, dst, [this](){ return m_ShouldContinue; }); + m_ShouldContinue = false; } - m_ShouldContinue = false; return Result; } @@ -52,7 +52,10 @@ bool cEvent::Wait(unsigned a_TimeoutMSec) void cEvent::Set(void) { - m_ShouldContinue = true; + { + std::unique_lock<std::mutex> Lock(m_Mutex); + m_ShouldContinue = true; + } m_CondVar.notify_one(); } @@ -61,7 +64,10 @@ void cEvent::Set(void) void cEvent::SetAll(void) { - m_ShouldContinue = true; + { + std::unique_lock<std::mutex> Lock(m_Mutex); + m_ShouldContinue = true; + } m_CondVar.notify_all(); } diff --git a/src/OSSupport/Event.h b/src/OSSupport/Event.h index 2c58ba485..067a2207c 100644 --- a/src/OSSupport/Event.h +++ b/src/OSSupport/Event.h @@ -12,7 +12,6 @@ #include <mutex> #include <condition_variable> -#include <atomic> @@ -42,7 +41,7 @@ public: private: /** Used for checking for spurious wakeups. */ - std::atomic<bool> m_ShouldContinue; + bool m_ShouldContinue; /** Mutex protecting m_ShouldContinue from multithreaded access. */ std::mutex m_Mutex; |