Skip to content

Commit

Permalink
__tsan_atomic64_store(&rbuf->readIndex, readIndex, __tsan_memory_orde…
Browse files Browse the repository at this point in the history
…r_relaxed);
  • Loading branch information
daschuer authored Nov 19, 2024
1 parent 3f7342d commit 4ff2a82
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions lib/portaudio/pa_ringbuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ ring_buffer_size_t PaUtil_InitializeRingBuffer( PaUtilRingBuffer *rbuf, ring_buf
/***************************************************************************
** Return number of elements available for reading. */
ring_buffer_size_t PaUtil_GetRingBufferReadAvailable( const PaUtilRingBuffer *rbuf )
{
return ( (rbuf->writeIndex - rbuf->readIndex) & rbuf->bigMask );

return ( (__tsan_atomic64_load(&rbuf->writeIndex, __tsan_memory_order_relaxed) -

Check failure on line 82 in lib/portaudio/pa_ringbuffer.c

View workflow job for this annotation

GitHub Actions / clazy

expected function body after function declarator

Check failure on line 82 in lib/portaudio/pa_ringbuffer.c

View workflow job for this annotation

GitHub Actions / Ubuntu 24.04

expected declaration specifiers before ‘return’

Check failure on line 82 in lib/portaudio/pa_ringbuffer.c

View workflow job for this annotation

GitHub Actions / clang-tidy

expected function body after function declarator

Check failure on line 82 in lib/portaudio/pa_ringbuffer.c

View workflow job for this annotation

GitHub Actions / macOS 12 x64

expected function body after function declarator

Check failure on line 82 in lib/portaudio/pa_ringbuffer.c

View workflow job for this annotation

GitHub Actions / macOS 12 arm64

expected function body after function declarator

Check failure on line 82 in lib/portaudio/pa_ringbuffer.c

View workflow job for this annotation

GitHub Actions / coverage

expected declaration specifiers before ‘return’
__tsan_atomic64_load(&rbuf->readIndex, __tsan_memory_order_relaxed)) & rbuf->bigMask );
}

Check failure on line 84 in lib/portaudio/pa_ringbuffer.c

View workflow job for this annotation

GitHub Actions / clazy

extraneous closing brace ('}')

Check failure on line 84 in lib/portaudio/pa_ringbuffer.c

View workflow job for this annotation

GitHub Actions / Ubuntu 24.04

expected declaration specifiers before ‘}’ token

Check failure on line 84 in lib/portaudio/pa_ringbuffer.c

View workflow job for this annotation

GitHub Actions / clang-tidy

extraneous closing brace ('}')

Check failure on line 84 in lib/portaudio/pa_ringbuffer.c

View workflow job for this annotation

GitHub Actions / macOS 12 x64

extraneous closing brace ('}')

Check failure on line 84 in lib/portaudio/pa_ringbuffer.c

View workflow job for this annotation

GitHub Actions / macOS 12 arm64

extraneous closing brace ('}')

Check failure on line 84 in lib/portaudio/pa_ringbuffer.c

View workflow job for this annotation

GitHub Actions / coverage

expected declaration specifiers before ‘}’ token
/***************************************************************************
** Return number of elements available for writing. */
Expand All @@ -92,7 +93,8 @@ ring_buffer_size_t PaUtil_GetRingBufferWriteAvailable( const PaUtilRingBuffer *r
** Clear buffer. Should only be called when buffer is NOT being read or written. */
void PaUtil_FlushRingBuffer( PaUtilRingBuffer *rbuf )
{

Check failure on line 95 in lib/portaudio/pa_ringbuffer.c

View workflow job for this annotation

GitHub Actions / Ubuntu 24.04

expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token

Check failure on line 95 in lib/portaudio/pa_ringbuffer.c

View workflow job for this annotation

GitHub Actions / coverage

expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
rbuf->writeIndex = rbuf->readIndex = 0;
__tsan_atomic64_store(&rbuf->writeIndex, 0, __tsan_memory_order_relaxed);
__tsan_atomic64_store(&rbuf->readIndex, 0, __tsan_memory_order_relaxed);
}

/***************************************************************************
Expand All @@ -109,7 +111,7 @@ ring_buffer_size_t PaUtil_GetRingBufferWriteRegions( PaUtilRingBuffer *rbuf, rin
ring_buffer_size_t available = PaUtil_GetRingBufferWriteAvailable( rbuf );
if( elementCount > available ) elementCount = available;
/* Check to see if write is not contiguous. */
index = rbuf->writeIndex & rbuf->smallMask;
index = __tsan_atomic64_load(&rbuf->writeIndex, __tsan_memory_order_relaxed) & rbuf->smallMask;
if( (index + elementCount) > rbuf->bufferSize )
{
/* Write data in two blocks that wrap the buffer. */
Expand Down Expand Up @@ -142,7 +144,9 @@ ring_buffer_size_t PaUtil_AdvanceRingBufferWriteIndex( PaUtilRingBuffer *rbuf, r
(write after write)
*/
PaUtil_WriteMemoryBarrier();
return rbuf->writeIndex = (rbuf->writeIndex + elementCount) & rbuf->bigMask;
ring_buffer_size_t writeIndex = (rbuf->writeIndex + elementCount) & rbuf->bigMask;
__tsan_atomic64_store(&rbuf->writeIndex, writeIndex, __tsan_memory_order_relaxed);
return writeIndex;
}

/***************************************************************************
Expand All @@ -159,7 +163,7 @@ ring_buffer_size_t PaUtil_GetRingBufferReadRegions( PaUtilRingBuffer *rbuf, ring
ring_buffer_size_t available = PaUtil_GetRingBufferReadAvailable( rbuf ); /* doesn't use memory barrier */
if( elementCount > available ) elementCount = available;
/* Check to see if read is not contiguous. */
index = rbuf->readIndex & rbuf->smallMask;
index = __tsan_atomic64_load(&rbuf->readIndex, __tsan_memory_order_relaxed) & rbuf->smallMask;
if( (index + elementCount) > rbuf->bufferSize )
{
/* Write data in two blocks that wrap the buffer. */
Expand Down Expand Up @@ -190,7 +194,9 @@ ring_buffer_size_t PaUtil_AdvanceRingBufferReadIndex( PaUtilRingBuffer *rbuf, ri
(write-after-read) => full barrier
*/
PaUtil_FullMemoryBarrier();
return rbuf->readIndex = (rbuf->readIndex + elementCount) & rbuf->bigMask;
ring_buffer_size_t readIndex = (rbuf->readIndex + elementCount) & rbuf->bigMask;
__tsan_atomic64_store(&rbuf->readIndex, readIndex, __tsan_memory_order_relaxed);
return readIndex;
}

/***************************************************************************
Expand Down

0 comments on commit 4ff2a82

Please sign in to comment.