mirror of
https://github.com/yuzu-emu/yuzu.git
synced 2024-07-04 23:31:19 +01:00
Merge pull request #11433 from liamwhite/shutdown-oopsie
polyfill_thread: ensure mutex was locked before signaling stop
This commit is contained in:
commit
b5f99164f1
1 changed files with 13 additions and 7 deletions
|
@ -19,8 +19,8 @@
|
||||||
namespace Common {
|
namespace Common {
|
||||||
|
|
||||||
template <typename Condvar, typename Lock, typename Pred>
|
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) {
|
||||||
cv.wait(lock, token, std::move(pred));
|
cv.wait(lk, token, std::move(pred));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Rep, typename Period>
|
template <typename Rep, typename Period>
|
||||||
|
@ -332,13 +332,17 @@ private:
|
||||||
namespace Common {
|
namespace Common {
|
||||||
|
|
||||||
template <typename Condvar, typename Lock, typename Pred>
|
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()) {
|
if (token.stop_requested()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::stop_callback callback(token, [&] { cv.notify_all(); });
|
std::stop_callback callback(token, [&] {
|
||||||
cv.wait(lock, [&] { return pred() || token.stop_requested(); });
|
{ std::scoped_lock lk2{*lk.mutex()}; }
|
||||||
|
cv.notify_all();
|
||||||
|
});
|
||||||
|
|
||||||
|
cv.wait(lk, [&] { return pred() || token.stop_requested(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Rep, typename Period>
|
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, [&] {
|
std::stop_callback cb(token, [&] {
|
||||||
// Wake up the waiting thread.
|
// Wake up the waiting thread.
|
||||||
std::unique_lock lk{m};
|
{
|
||||||
|
std::scoped_lock lk{m};
|
||||||
stop_requested = true;
|
stop_requested = true;
|
||||||
|
}
|
||||||
cv.notify_one();
|
cv.notify_one();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue