summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbunnei <bunneidev@gmail.com>2020-09-01 03:21:38 +0200
committerGitHub <noreply@github.com>2020-09-01 03:21:38 +0200
commitad9ce67b5262e383050e5af629e2eda71391c2bd (patch)
treeb10e39893cbda958d218f5890bdc08c3517660d8
parentMerge pull request #4589 from ReinUsesLisp/tsan-host (diff)
parentcommon/thread: Fix data race in is_set (diff)
downloadyuzu-ad9ce67b5262e383050e5af629e2eda71391c2bd.tar
yuzu-ad9ce67b5262e383050e5af629e2eda71391c2bd.tar.gz
yuzu-ad9ce67b5262e383050e5af629e2eda71391c2bd.tar.bz2
yuzu-ad9ce67b5262e383050e5af629e2eda71391c2bd.tar.lz
yuzu-ad9ce67b5262e383050e5af629e2eda71391c2bd.tar.xz
yuzu-ad9ce67b5262e383050e5af629e2eda71391c2bd.tar.zst
yuzu-ad9ce67b5262e383050e5af629e2eda71391c2bd.zip
-rw-r--r--src/common/thread.h9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/common/thread.h b/src/common/thread.h
index 52b359413..a8c17c71a 100644
--- a/src/common/thread.h
+++ b/src/common/thread.h
@@ -4,6 +4,7 @@
#pragma once
+#include <atomic>
#include <chrono>
#include <condition_variable>
#include <cstddef>
@@ -25,13 +26,13 @@ public:
void Wait() {
std::unique_lock lk{mutex};
- condvar.wait(lk, [&] { return is_set; });
+ condvar.wait(lk, [&] { return is_set.load(); });
is_set = false;
}
bool WaitFor(const std::chrono::nanoseconds& time) {
std::unique_lock lk{mutex};
- if (!condvar.wait_for(lk, time, [this] { return is_set; }))
+ if (!condvar.wait_for(lk, time, [this] { return is_set.load(); }))
return false;
is_set = false;
return true;
@@ -40,7 +41,7 @@ public:
template <class Clock, class Duration>
bool WaitUntil(const std::chrono::time_point<Clock, Duration>& time) {
std::unique_lock lk{mutex};
- if (!condvar.wait_until(lk, time, [this] { return is_set; }))
+ if (!condvar.wait_until(lk, time, [this] { return is_set.load(); }))
return false;
is_set = false;
return true;
@@ -54,9 +55,9 @@ public:
}
private:
- bool is_set = false;
std::condition_variable condvar;
std::mutex mutex;
+ std::atomic_bool is_set{false};
};
class Barrier {