diff options
Diffstat (limited to 'src/common/ring_buffer.h')
| -rw-r--r-- | src/common/ring_buffer.h | 14 |
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 @@ | |||
| 9 | #include <atomic> | 9 | #include <atomic> |
| 10 | #include <cstddef> | 10 | #include <cstddef> |
| 11 | #include <cstring> | 11 | #include <cstring> |
| 12 | #include <new> | ||
| 12 | #include <type_traits> | 13 | #include <type_traits> |
| 13 | #include <vector> | 14 | #include <vector> |
| 14 | #include "common/common_types.h" | 15 | #include "common/common_types.h" |
| @@ -29,7 +30,7 @@ class RingBuffer { | |||
| 29 | static_assert(capacity < std::numeric_limits<std::size_t>::max() / 2 / granularity); | 30 | static_assert(capacity < std::numeric_limits<std::size_t>::max() / 2 / granularity); |
| 30 | static_assert((capacity & (capacity - 1)) == 0, "capacity must be a power of two"); | 31 | static_assert((capacity & (capacity - 1)) == 0, "capacity must be a power of two"); |
| 31 | // Ensure lock-free. | 32 | // Ensure lock-free. |
| 32 | static_assert(std::atomic<std::size_t>::is_always_lock_free); | 33 | static_assert(std::atomic_size_t::is_always_lock_free); |
| 33 | 34 | ||
| 34 | public: | 35 | public: |
| 35 | /// Pushes slots into the ring buffer | 36 | /// Pushes slots into the ring buffer |
| @@ -102,8 +103,15 @@ public: | |||
| 102 | private: | 103 | private: |
| 103 | // It is important to align the below variables for performance reasons: | 104 | // It is important to align the below variables for performance reasons: |
| 104 | // Having them on the same cache-line would result in false-sharing between them. | 105 | // Having them on the same cache-line would result in false-sharing between them. |
| 105 | alignas(128) std::atomic<std::size_t> m_read_index{0}; | 106 | // TODO: Remove this ifdef whenever clang and GCC support |
| 106 | alignas(128) std::atomic<std::size_t> m_write_index{0}; | 107 | // std::hardware_destructive_interference_size. |
| 108 | #if defined(_MSC_VER) && _MSC_VER >= 1911 | ||
| 109 | alignas(std::hardware_destructive_interference_size) std::atomic_size_t m_read_index{0}; | ||
| 110 | alignas(std::hardware_destructive_interference_size) std::atomic_size_t m_write_index{0}; | ||
| 111 | #else | ||
| 112 | alignas(128) std::atomic_size_t m_read_index{0}; | ||
| 113 | alignas(128) std::atomic_size_t m_write_index{0}; | ||
| 114 | #endif | ||
| 107 | 115 | ||
| 108 | std::array<T, granularity * capacity> m_data; | 116 | std::array<T, granularity * capacity> m_data; |
| 109 | }; | 117 | }; |