mirror of
https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git
synced 2025-07-18 11:19:10 +00:00
Merge pull request #447 from zrax/hsEvent_fix
Fix hsEvent to match the old behavior better
This commit is contained in:
@ -175,19 +175,34 @@ class hsEvent
|
|||||||
{
|
{
|
||||||
std::mutex fMutex;
|
std::mutex fMutex;
|
||||||
std::condition_variable fCondition;
|
std::condition_variable fCondition;
|
||||||
|
bool fEvent;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
hsEvent() { }
|
hsEvent() : fEvent(false) { }
|
||||||
|
|
||||||
inline void Wait()
|
inline void Wait()
|
||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> lock(fMutex);
|
std::unique_lock<std::mutex> lock(fMutex);
|
||||||
fCondition.wait(lock);
|
fCondition.wait(lock, [this]() { return fEvent; });
|
||||||
|
fEvent = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class _Rep, class _Period>
|
||||||
|
inline bool Wait(const std::chrono::duration<_Rep, _Period> &duration)
|
||||||
|
{
|
||||||
|
std::unique_lock<std::mutex> lock(fMutex);
|
||||||
|
|
||||||
|
bool result = fCondition.wait_for(lock, duration, [this]() { return fEvent; });
|
||||||
|
if (result)
|
||||||
|
fEvent = false;
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void Signal()
|
inline void Signal()
|
||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> lock(fMutex);
|
std::unique_lock<std::mutex> lock(fMutex);
|
||||||
|
fEvent = true;
|
||||||
fCondition.notify_one();
|
fCondition.notify_one();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user