ZXFoundation™ 26h2
Loading...
Searching...
No Matches
lib::ring_buffer< N > Class Template Referenceexport

A lock-free byte-stream ring buffer (mirrors Linux kfifo). More...

Public Member Functions

constexpr auto capacity () const noexcept -> usize
 Returns the total capacity of the buffer.
auto peek (std::span< u8 > buf, usize start_offset=0) const noexcept -> usize
 Peek data without moving the head pointer.
auto pop (std::span< u8 > buf) noexcept -> usize
 Pop data from the ring buffer.
auto push (std::span< const u8 > buf) noexcept -> usize
 Push data into the ring buffer.
auto size () const noexcept -> usize
 Returns the total number of bytes currently in the buffer.

Detailed Description

template<usize N>
requires ((N > 0) && ((N & (N - 1)) == 0))
class lib::ring_buffer< N >

A lock-free byte-stream ring buffer (mirrors Linux kfifo).

Template Parameters
NCapacity of the buffer (MUST be a power of two).

Member Function Documentation

◆ pop()

template<usize N>
auto lib::ring_buffer< N >::pop ( std::span< u8 > buf) ->usize
inlineexportnoexcept

Pop data from the ring buffer.

Parameters
[out]bufDestination buffer.
Returns
Number of bytes actually read.

◆ push()

template<usize N>
auto lib::ring_buffer< N >::push ( std::span< const u8 > buf) ->usize
inlineexportnoexcept

Push data into the ring buffer.

Parameters
[in]bufSource buffer.
Returns
Number of bytes actually written.
Note
This implementation is lockless for single-producer. For multiple producers, external locking is required.

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