1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-07-22 07:28:03 +02:00

Avoid false sharing of the two atomic variables of RingBuffer

This commit is contained in:
Paul Licameli 2018-06-21 12:09:32 -04:00
parent f145574dd6
commit bd7e6f7279

View File

@ -39,10 +39,32 @@ class RingBuffer {
size_t Filled( size_t start, size_t end );
size_t Free( size_t start, size_t end );
sampleFormat mFormat;
std::atomic<size_t> mStart { 0 };
std::atomic<size_t> mEnd { 0 };
enum : size_t { CacheLine = 64 };
/*
// We will do this in C++17 instead:
static constexpr size_t CacheLine =
std::hardware_destructive_interference_size;
*/
// Align the two atomics to avoid false sharing
// TODO MSVC2017: use alignas
#ifdef __WXMSW__
__declspec(align(64))
#else
alignas(CacheLine)
#endif
std::atomic<size_t> mStart { 0 };
#ifdef __WXMSW__
__declspec(align(64))
#else
alignas(CacheLine)
#endif
std::atomic<size_t> mEnd{ 0 };
const size_t mBufferSize;
sampleFormat mFormat;
SampleBuffer mBuffer;
};