diff --git a/Common/Thread/Event.h b/Common/Thread/Event.h index 705d8efc1f..3cc773da72 100644 --- a/Common/Thread/Event.h +++ b/Common/Thread/Event.h @@ -12,8 +12,8 @@ public: } void Wait() override { + std::unique_lock lock; if (!triggered_) { - std::unique_lock lock; cond_.wait(lock, [&] { return triggered_.load(); }); } } diff --git a/Common/Thread/Waitable.h b/Common/Thread/Waitable.h index 1f38bf33d8..9008b2fa21 100644 --- a/Common/Thread/Waitable.h +++ b/Common/Thread/Waitable.h @@ -12,18 +12,18 @@ public: } void Wait() override { + std::unique_lock lock(mutex_); if (!triggered_) { - std::unique_lock lock(mutex_); cond_.wait(lock, [&] { return triggered_.load(); }); } } bool WaitFor(double budget) { uint32_t us = budget > 0 ? (uint32_t)(budget * 1000000.0) : 0; + std::unique_lock lock(mutex_); if (!triggered_) { if (us == 0) return false; - std::unique_lock lock(mutex_); cond_.wait_for(lock, std::chrono::microseconds(us), [&] { return triggered_.load(); }); } return triggered_;