Small fix for cEvent
Don't bother using atomics since a synchronisation primitive is already being used.
This commit is contained in:
parent
69a44b2fee
commit
dfc0f2ae00
@ -25,9 +25,9 @@ void cEvent::Wait(void)
|
|||||||
{
|
{
|
||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> Lock(m_Mutex);
|
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;
|
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
|
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;
|
return Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,7 +52,10 @@ bool cEvent::Wait(unsigned a_TimeoutMSec)
|
|||||||
|
|
||||||
void cEvent::Set(void)
|
void cEvent::Set(void)
|
||||||
{
|
{
|
||||||
|
{
|
||||||
|
std::unique_lock<std::mutex> Lock(m_Mutex);
|
||||||
m_ShouldContinue = true;
|
m_ShouldContinue = true;
|
||||||
|
}
|
||||||
m_CondVar.notify_one();
|
m_CondVar.notify_one();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,7 +64,10 @@ void cEvent::Set(void)
|
|||||||
|
|
||||||
void cEvent::SetAll(void)
|
void cEvent::SetAll(void)
|
||||||
{
|
{
|
||||||
|
{
|
||||||
|
std::unique_lock<std::mutex> Lock(m_Mutex);
|
||||||
m_ShouldContinue = true;
|
m_ShouldContinue = true;
|
||||||
|
}
|
||||||
m_CondVar.notify_all();
|
m_CondVar.notify_all();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
|
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <condition_variable>
|
#include <condition_variable>
|
||||||
#include <atomic>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -42,7 +41,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
|
|
||||||
/** Used for checking for spurious wakeups. */
|
/** Used for checking for spurious wakeups. */
|
||||||
std::atomic<bool> m_ShouldContinue;
|
bool m_ShouldContinue;
|
||||||
|
|
||||||
/** Mutex protecting m_ShouldContinue from multithreaded access. */
|
/** Mutex protecting m_ShouldContinue from multithreaded access. */
|
||||||
std::mutex m_Mutex;
|
std::mutex m_Mutex;
|
||||||
|
Loading…
Reference in New Issue
Block a user