diff options
| author | Martin Ridgers <[email protected]> | 2021-11-11 10:18:16 +0100 |
|---|---|---|
| committer | Martin Ridgers <[email protected]> | 2021-11-11 10:18:16 +0100 |
| commit | 96d5783db2f50b56fc0440c35b1033045bee0b54 (patch) | |
| tree | bfa1a678a5c390ff457489ef2040a003e1604b1c /zencore/thread.cpp | |
| parent | Windows unreachable code compile fix (diff) | |
| download | zen-96d5783db2f50b56fc0440c35b1033045bee0b54.tar.xz zen-96d5783db2f50b56fc0440c35b1033045bee0b54.zip | |
Check if an event is already set before waiting on it
Diffstat (limited to 'zencore/thread.cpp')
| -rw-r--r-- | zencore/thread.cpp | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/zencore/thread.cpp b/zencore/thread.cpp index e422d7ce3..3e40b6336 100644 --- a/zencore/thread.cpp +++ b/zencore/thread.cpp @@ -200,6 +200,12 @@ Event::Wait(int TimeoutMs) if (TimeoutMs >= 0) { std::unique_lock Lock(Inner->Mutex); + + if (Inner->bSet) + { + return true; + } + return Inner->CondVar.wait_for( Lock, std::chrono::milliseconds(TimeoutMs), @@ -208,7 +214,12 @@ Event::Wait(int TimeoutMs) } std::unique_lock Lock(Inner->Mutex); - Inner->CondVar.wait(Lock, [&] { return Inner->bSet; }); + + if (!Inner->bSet) + { + Inner->CondVar.wait(Lock, [&] { return Inner->bSet; }); + } + return true; #endif } |