mirror of
https://github.com/yuzu-emu/yuzu.git
synced 2024-11-23 13:35:38 +01:00
Merge pull request #6868 from yzct12345/safe-threads-no-deadlocks
threadsafe_queue: Fix deadlock
This commit is contained in:
commit
bdd617da03
@ -46,15 +46,13 @@ public:
|
|||||||
ElementPtr* new_ptr = new ElementPtr();
|
ElementPtr* new_ptr = new ElementPtr();
|
||||||
write_ptr->next.store(new_ptr, std::memory_order_release);
|
write_ptr->next.store(new_ptr, std::memory_order_release);
|
||||||
write_ptr = new_ptr;
|
write_ptr = new_ptr;
|
||||||
|
++size;
|
||||||
|
|
||||||
const size_t previous_size{size++};
|
// cv_mutex must be held or else there will be a missed wakeup if the other thread is in the
|
||||||
|
// line before cv.wait
|
||||||
// Acquire the mutex and then immediately release it as a fence.
|
|
||||||
// TODO(bunnei): This can be replaced with C++20 waitable atomics when properly supported.
|
// TODO(bunnei): This can be replaced with C++20 waitable atomics when properly supported.
|
||||||
// See discussion on https://github.com/yuzu-emu/yuzu/pull/3173 for details.
|
// See discussion on https://github.com/yuzu-emu/yuzu/pull/3173 for details.
|
||||||
if (previous_size == 0) {
|
std::lock_guard lock{cv_mutex};
|
||||||
std::lock_guard lock{cv_mutex};
|
|
||||||
}
|
|
||||||
cv.notify_one();
|
cv.notify_one();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user