Fix misuses of cond.wait (should return true when you want to stop waiting!)

This commit is contained in:
Henrik Rydgård committed 2022-04-08 12:28:45 +02:00
1 parent 5b20ace502
commit bde54ccdc0
3 files changed
+13 -8

No files matched your search

+8 -5
View File
@@ -7,12 +7,15 @@
struct Event : public Waitable {
public:
Event() {
triggered_ = false;
}
void Wait() override {
if (triggered_) {
return;
if (!triggered_) {
std::unique_lock<std::mutex> lock;
cond_.wait(lock, [&] { return triggered_.load(); });
}
std::unique_lock<std::mutex> lock;
cond_.wait(lock, [&] { return !triggered_; });
}
void Notify() {
@@ -24,5 +27,5 @@ public:
private:
std::condition_variable cond_;
std::mutex mutex_;
bool triggered_ = false;
std::atomic<bool> triggered_;
};