Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
roc::core::SpscByteBuffer Class Reference

Thread-safe lock-free single-producer single-consumer circular buffer of byte chunks. More...

#include <spsc_byte_buffer.h>

Inheritance diagram for roc::core::SpscByteBuffer:
Collaboration diagram for roc::core::SpscByteBuffer:

Public Member Functions

 SpscByteBuffer (IArena &arena, size_t chunk_size, size_t n_chunks)
 Initialize. More...
 
 ~SpscByteBuffer ()
 Deinitialize. More...
 
bool is_valid () const
 Check that initial allocation succeeded. More...
 
bool is_empty () const
 Check if buffer is empty. More...
 
uint8_t * begin_write ()
 Begin writing of a chunk. If buffer is full, returns NULL. Should be called from writer thread. Lock-free. More...
 
void end_write ()
 End writing of a chunk. Should be called if and only if begin_write() returned non-NULL. Should be called from writer thread. Lock-free. More...
 
uint8_t * begin_read ()
 Begin reading of a chunk. If buffer is empty, returns NULL. Should be called from reader thread. Lock-free. More...
 
void end_read ()
 End reading of a chunk. Should be called if and only if begin_read() returned non-NULL. Should be called from reader thread. Lock-free. More...
 

Detailed Description

Thread-safe lock-free single-producer single-consumer circular buffer of byte chunks.

Allows access from two concurrent threads: writer and reader. Both writer and reader are never blocked. Provides sequential consistency.

Definition at line 28 of file spsc_byte_buffer.h.

Constructor & Destructor Documentation

◆ SpscByteBuffer()

roc::core::SpscByteBuffer::SpscByteBuffer ( IArena arena,
size_t  chunk_size,
size_t  n_chunks 
)

Initialize.

◆ ~SpscByteBuffer()

roc::core::SpscByteBuffer::~SpscByteBuffer ( )

Deinitialize.

Member Function Documentation

◆ begin_read()

uint8_t* roc::core::SpscByteBuffer::begin_read ( )

Begin reading of a chunk. If buffer is empty, returns NULL. Should be called from reader thread. Lock-free.

◆ begin_write()

uint8_t* roc::core::SpscByteBuffer::begin_write ( )

Begin writing of a chunk. If buffer is full, returns NULL. Should be called from writer thread. Lock-free.

◆ end_read()

void roc::core::SpscByteBuffer::end_read ( )

End reading of a chunk. Should be called if and only if begin_read() returned non-NULL. Should be called from reader thread. Lock-free.

◆ end_write()

void roc::core::SpscByteBuffer::end_write ( )

End writing of a chunk. Should be called if and only if begin_write() returned non-NULL. Should be called from writer thread. Lock-free.

◆ is_empty()

bool roc::core::SpscByteBuffer::is_empty ( ) const

Check if buffer is empty.

◆ is_valid()

bool roc::core::SpscByteBuffer::is_valid ( ) const

Check that initial allocation succeeded.


The documentation for this class was generated from the following file: