Merge pull request #3173 from yuzu-emu/bunnei-spscqueue

common: SPSCQueue: Notify after incrementing queue size.
merge-requests/60/head
bunnei 2019-12-17 14:11:20 +07:00 committed by GitHub
commit 8825b88a45
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 2 deletions

@ -46,9 +46,16 @@ 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;
cv.notify_one();
++size; const size_t previous_size{size++};
// 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.
// See discussion on https://github.com/yuzu-emu/yuzu/pull/3173 for details.
if (previous_size == 0) {
std::lock_guard lock{cv_mutex};
}
cv.notify_one();
} }
void Pop() { void Pop() {