diff options
author | liamwhite <liamwhite@users.noreply.github.com> | 2023-09-14 15:24:20 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-14 15:24:20 +0200 |
commit | b5f99164f1c9e5fb693186f5c83feed2bdb3cd4d (patch) | |
tree | 317214a03ffabb0ee2b4cc57d519dbf45960a31a | |
parent | shader_recompiler: skip sampler for buffer textures (#11435) (diff) | |
parent | polyfill_thread: ensure mutex was locked before signaling stop (diff) | |
download | yuzu-b5f99164f1c9e5fb693186f5c83feed2bdb3cd4d.tar yuzu-b5f99164f1c9e5fb693186f5c83feed2bdb3cd4d.tar.gz yuzu-b5f99164f1c9e5fb693186f5c83feed2bdb3cd4d.tar.bz2 yuzu-b5f99164f1c9e5fb693186f5c83feed2bdb3cd4d.tar.lz yuzu-b5f99164f1c9e5fb693186f5c83feed2bdb3cd4d.tar.xz yuzu-b5f99164f1c9e5fb693186f5c83feed2bdb3cd4d.tar.zst yuzu-b5f99164f1c9e5fb693186f5c83feed2bdb3cd4d.zip |
Diffstat (limited to '')
-rw-r--r-- | src/common/polyfill_thread.h | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/src/common/polyfill_thread.h b/src/common/polyfill_thread.h index b5ef055db..41cbb9ed5 100644 --- a/src/common/polyfill_thread.h +++ b/src/common/polyfill_thread.h @@ -19,8 +19,8 @@ namespace Common { template <typename Condvar, typename Lock, typename Pred> -void CondvarWait(Condvar& cv, Lock& lock, std::stop_token token, Pred&& pred) { - cv.wait(lock, token, std::move(pred)); +void CondvarWait(Condvar& cv, std::unique_lock<Lock>& lk, std::stop_token token, Pred&& pred) { + cv.wait(lk, token, std::move(pred)); } template <typename Rep, typename Period> @@ -332,13 +332,17 @@ private: namespace Common { template <typename Condvar, typename Lock, typename Pred> -void CondvarWait(Condvar& cv, Lock& lock, std::stop_token token, Pred pred) { +void CondvarWait(Condvar& cv, std::unique_lock<Lock>& lk, std::stop_token token, Pred pred) { if (token.stop_requested()) { return; } - std::stop_callback callback(token, [&] { cv.notify_all(); }); - cv.wait(lock, [&] { return pred() || token.stop_requested(); }); + std::stop_callback callback(token, [&] { + { std::scoped_lock lk2{*lk.mutex()}; } + cv.notify_all(); + }); + + cv.wait(lk, [&] { return pred() || token.stop_requested(); }); } template <typename Rep, typename Period> @@ -353,8 +357,10 @@ bool StoppableTimedWait(std::stop_token token, const std::chrono::duration<Rep, std::stop_callback cb(token, [&] { // Wake up the waiting thread. - std::unique_lock lk{m}; - stop_requested = true; + { + std::scoped_lock lk{m}; + stop_requested = true; + } cv.notify_one(); }); |