diff options
author | bunnei <bunneidev@gmail.com> | 2019-12-17 20:11:20 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-12-17 20:11:20 +0100 |
commit | 8825b88a4589c249e9faa53f3ec90e582fa64198 (patch) | |
tree | ed8924086e528f13e5d38b100cad9a38e06c4d3a /src | |
parent | Merge pull request #3182 from ReinUsesLisp/renderer-opengl (diff) | |
parent | common: SPSCQueue: Notify after incrementing queue size. (diff) | |
download | yuzu-8825b88a4589c249e9faa53f3ec90e582fa64198.tar yuzu-8825b88a4589c249e9faa53f3ec90e582fa64198.tar.gz yuzu-8825b88a4589c249e9faa53f3ec90e582fa64198.tar.bz2 yuzu-8825b88a4589c249e9faa53f3ec90e582fa64198.tar.lz yuzu-8825b88a4589c249e9faa53f3ec90e582fa64198.tar.xz yuzu-8825b88a4589c249e9faa53f3ec90e582fa64198.tar.zst yuzu-8825b88a4589c249e9faa53f3ec90e582fa64198.zip |
Diffstat (limited to 'src')
-rw-r--r-- | src/common/threadsafe_queue.h | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/common/threadsafe_queue.h b/src/common/threadsafe_queue.h index e714ba5b3..8268bbd5c 100644 --- a/src/common/threadsafe_queue.h +++ b/src/common/threadsafe_queue.h @@ -46,9 +46,16 @@ public: ElementPtr* new_ptr = new ElementPtr(); write_ptr->next.store(new_ptr, std::memory_order_release); 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() { |