chrono::ros::ipc::RingBuffer Class Reference

Description

Lock-free ring buffer for single producer, single consumer Thread-safe for one writer thread and one reader thread.

#include <ChROSRingBuffer.h>

Public Member Functions

 RingBuffer (void *buffer, size_t size)
 Constructor. More...
 
bool Write (const void *data, size_t size)
 Write data to the ring buffer. More...
 
bool Read (void *data, size_t size)
 Read data from the ring buffer. More...
 
size_t Available () const
 Peek at available data without consuming it. More...
 
size_t Space () const
 Get free space available for writing. More...
 
bool IsEmpty () const
 Check if buffer is empty.
 
bool IsFull () const
 Check if buffer is full

 
void Clear ()
 Clear the buffer (not thread-safe, use only when no concurrent access)
 
bool Write (const void *data1, size_t size1, const void *data2, size_t size2)
 Write two data chunks to the ring buffer atomically This ensures that the reader sees either both chunks or neither, preventing race conditions. More...
 

Constructor & Destructor Documentation

◆ RingBuffer()

chrono::ros::ipc::RingBuffer::RingBuffer ( void *  buffer,
size_t  size 
)

Constructor.

Parameters
bufferPointer to memory buffer (must be power-of-2 size)
sizeSize of buffer in bytes (must be power of 2)

Member Function Documentation

◆ Available()

size_t chrono::ros::ipc::RingBuffer::Available ( ) const

Peek at available data without consuming it.

Returns
Number of bytes available to read

◆ Read()

bool chrono::ros::ipc::RingBuffer::Read ( void *  data,
size_t  size 
)

Read data from the ring buffer.

Parameters
dataPointer to buffer to read into
sizeNumber of bytes to read
Returns
true if successful, false if not enough data available

◆ Space()

size_t chrono::ros::ipc::RingBuffer::Space ( ) const

Get free space available for writing.

Returns
Number of bytes available to write

◆ Write() [1/2]

bool chrono::ros::ipc::RingBuffer::Write ( const void *  data,
size_t  size 
)

Write data to the ring buffer.

Parameters
dataPointer to data to write
sizeNumber of bytes to write
Returns
true if successful, false if not enough space

◆ Write() [2/2]

bool chrono::ros::ipc::RingBuffer::Write ( const void *  data1,
size_t  size1,
const void *  data2,
size_t  size2 
)

Write two data chunks to the ring buffer atomically This ensures that the reader sees either both chunks or neither, preventing race conditions.

Parameters
data1Pointer to first data chunk
size1Size of first data chunk
data2Pointer to second data chunk
size2Size of second data chunk
Returns
true if successful, false if not enough space

The documentation for this class was generated from the following files:
  • /builds/uwsbel/chrono/src/chrono_ros/ipc/ChROSRingBuffer.h
  • /builds/uwsbel/chrono/src/chrono_ros/ipc/ChROSRingBuffer.cpp