1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-10-22 06:22:58 +02:00

Stricter memory ordering in RingBuffer

This commit is contained in:
Paul Licameli
2018-06-21 13:40:01 -04:00
parent bd7e6f7279
commit fcdfd68d73

View File

@@ -54,9 +54,8 @@ size_t RingBuffer::Free( size_t start, size_t end )
// //
// For the writer only: // For the writer only:
// Only writer writes the end, so it can read it again relaxed // Only writer writes the end, so it can read it again relaxed
// And it reads the start written by reader, but reader sends no other // And it reads the start written by reader, with acquire order,
// information needing to synchronize with the start, so relaxed memory order // so that any reading done in Get() happens-before any reuse of the space.
// is good there too
// //
size_t RingBuffer::AvailForPut() size_t RingBuffer::AvailForPut()
@@ -72,7 +71,7 @@ size_t RingBuffer::AvailForPut()
size_t RingBuffer::Put(samplePtr buffer, sampleFormat format, size_t RingBuffer::Put(samplePtr buffer, sampleFormat format,
size_t samplesToCopy) size_t samplesToCopy)
{ {
auto start = mStart.load( std::memory_order_relaxed ); auto start = mStart.load( std::memory_order_acquire );
auto end = mEnd.load( std::memory_order_relaxed ); auto end = mEnd.load( std::memory_order_relaxed );
samplesToCopy = std::min( samplesToCopy, Free( start, end ) ); samplesToCopy = std::min( samplesToCopy, Free( start, end ) );
auto src = buffer; auto src = buffer;
@@ -167,7 +166,7 @@ size_t RingBuffer::Get(samplePtr buffer, sampleFormat format,
} }
// Communicate to writer that we have consumed some data, and that's all // Communicate to writer that we have consumed some data, and that's all
mStart.store( start, std::memory_order_relaxed ); mStart.store( start, std::memory_order_release );
return copied; return copied;
} }