summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorbunnei <bunneidev@gmail.com>2018-09-21 05:29:10 +0200
committerGitHub <noreply@github.com>2018-09-21 05:29:10 +0200
commita0db7e2cf990bddcb889709447bf065ff5c9d4a4 (patch)
tree421a66496f98d2f228ac87d9ec4cf30e18dd71bd /src
parentMerge pull request #1373 from ogniK5377/revert-nifm (diff)
parentring_buffer: Use std::atomic_size_t in a static assert (diff)
downloadyuzu-a0db7e2cf990bddcb889709447bf065ff5c9d4a4.tar
yuzu-a0db7e2cf990bddcb889709447bf065ff5c9d4a4.tar.gz
yuzu-a0db7e2cf990bddcb889709447bf065ff5c9d4a4.tar.bz2
yuzu-a0db7e2cf990bddcb889709447bf065ff5c9d4a4.tar.lz
yuzu-a0db7e2cf990bddcb889709447bf065ff5c9d4a4.tar.xz
yuzu-a0db7e2cf990bddcb889709447bf065ff5c9d4a4.tar.zst
yuzu-a0db7e2cf990bddcb889709447bf065ff5c9d4a4.zip
Diffstat (limited to 'src')
-rw-r--r--src/common/ring_buffer.h14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/common/ring_buffer.h b/src/common/ring_buffer.h
index 45926c9ec..abe3b4dc2 100644
--- a/src/common/ring_buffer.h
+++ b/src/common/ring_buffer.h
@@ -9,6 +9,7 @@
#include <atomic>
#include <cstddef>
#include <cstring>
+#include <new>
#include <type_traits>
#include <vector>
#include "common/common_types.h"
@@ -29,7 +30,7 @@ class RingBuffer {
static_assert(capacity < std::numeric_limits<std::size_t>::max() / 2 / granularity);
static_assert((capacity & (capacity - 1)) == 0, "capacity must be a power of two");
// Ensure lock-free.
- static_assert(std::atomic<std::size_t>::is_always_lock_free);
+ static_assert(std::atomic_size_t::is_always_lock_free);
public:
/// Pushes slots into the ring buffer
@@ -102,8 +103,15 @@ public:
private:
// It is important to align the below variables for performance reasons:
// Having them on the same cache-line would result in false-sharing between them.
- alignas(128) std::atomic<std::size_t> m_read_index{0};
- alignas(128) std::atomic<std::size_t> m_write_index{0};
+ // TODO: Remove this ifdef whenever clang and GCC support
+ // std::hardware_destructive_interference_size.
+#if defined(_MSC_VER) && _MSC_VER >= 1911
+ alignas(std::hardware_destructive_interference_size) std::atomic_size_t m_read_index{0};
+ alignas(std::hardware_destructive_interference_size) std::atomic_size_t m_write_index{0};
+#else
+ alignas(128) std::atomic_size_t m_read_index{0};
+ alignas(128) std::atomic_size_t m_write_index{0};
+#endif
std::array<T, granularity * capacity> m_data;
};