Merge branch 'ring_buffer_fix' into 'main'

fix: Stable & Predictable 64-byte

See merge request citron/emulator!90
This commit is contained in:
Zephyron
2025-10-07 15:47:34 +10:00

View File

@@ -100,17 +100,11 @@ public:
} }
private: private:
// It is important to align the below variables for performance reasons: // Use a fixed cache-line size of 64 bytes to prevent false sharing. This avoids
// Having them on the same cache-line would result in false-sharing between them. // [-Winterference-size] warnings by providing a stable ABI. 64 is a common
// TODO: Remove this ifdef whenever clang and GCC support // value for modern CPUs.
// std::hardware_destructive_interference_size. alignas(64) std::atomic_size_t m_read_index{0};
#ifdef __cpp_lib_hardware_interference_size alignas(64) std::atomic_size_t m_write_index{0};
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, capacity> m_data; std::array<T, capacity> m_data;
}; };