template <AllocatorType Allocator>
class SpscBuffer
Defined at line 43 of file ../../zircon/kernel/lib/spsc_buffer/include/lib/spsc_buffer/spsc_buffer.h
SpscBuffer implements a transactional, single-producer, single-consumer ring buffer.
The caller is responsible for ensuring that there is only one reader and one writer; no internal
synchronization is provided to enforce this constraint.
The caller is also responsible for providing the underlying memory region in which to store
data. A span pointing to this buffer must be provided to the Init method before Read/Reserve can
be called. Note that this backing buffer must have a size that is a power of two for correct
functionality.
Public Methods
void SpscBuffer<Allocator> ()
Defined at line 45 of file ../../zircon/kernel/lib/spsc_buffer/include/lib/spsc_buffer/spsc_buffer.h
void ~SpscBuffer<Allocator> ()
Defined at line 46 of file ../../zircon/kernel/lib/spsc_buffer/include/lib/spsc_buffer/spsc_buffer.h
void SpscBuffer<Allocator> (const SpscBuffer<Allocator> & )
An SpscBuffer should be initialized once and never moved or copied.
Defined at line 49 of file ../../zircon/kernel/lib/spsc_buffer/include/lib/spsc_buffer/spsc_buffer.h
SpscBuffer<Allocator> & operator= (const SpscBuffer<Allocator> & )
Defined at line 50 of file ../../zircon/kernel/lib/spsc_buffer/include/lib/spsc_buffer/spsc_buffer.h
void SpscBuffer<Allocator> (SpscBuffer<Allocator> && )
Defined at line 51 of file ../../zircon/kernel/lib/spsc_buffer/include/lib/spsc_buffer/spsc_buffer.h
SpscBuffer<Allocator> operator= (SpscBuffer<Allocator> && )
Defined at line 52 of file ../../zircon/kernel/lib/spsc_buffer/include/lib/spsc_buffer/spsc_buffer.h
zx_status_t Init (uint32_t size)
Initializes a buffer of the given size.
Defined at line 55 of file ../../zircon/kernel/lib/spsc_buffer/include/lib/spsc_buffer/spsc_buffer.h
zx::result<Reservation> Reserve (uint32_t size)
Reserves a block of the given size in the buffer.
Any data written into this block will not be visible to readers until Commit is called on the
Reservation.
Defined at line 191 of file ../../zircon/kernel/lib/spsc_buffer/include/lib/spsc_buffer/spsc_buffer.h
template <CopyOutFunction CopyFunc>
zx::result<uint32_t> Read (CopyFunc copy_fn, uint32_t len)
Copies len bytes out of the buffer and into dst.
Takes a CopyOutFunction as the first argument, which has the following signature:
zx_status_t copy_fn(uint32_t offset, ktl::span
<ktl
::byte> src);
where offset is the offset into the destination buffer at which we data should be written, and
src is the source buffer. This copy function may be invoked multiple times during the course
of this function.
Returns the number of bytes read into dst on success. If copy_fn returns an error, that error
will be returned to the caller of Read.
Importantly, even if an error is returned, 'copy_fn' might have already processed a partial
amount of data (between 0 and 'len' bytes). However, these partially processed bytes are
considered *not read* by this 'Read' function. Consequently, the internal read pointer of the
ring buffer will *not* be advanced for these unread bytes, meaning that these same bytes will
remain available for reading in subsequent calls to 'Read'.
Defined at line 230 of file ../../zircon/kernel/lib/spsc_buffer/include/lib/spsc_buffer/spsc_buffer.h
void Drain ()
Empties the contents of the buffer. This is logically a Read operation, so a Read and Drain
cannot be called concurrently. Additionally, the behavior of this method is non-deterministic
if a Write is in-progress; the Drain may empty the buffer completely, or it may empty out all
data up to the beginning of the in-progress write. If callers wish to use this method to
deterministically empty the buffer, they will need to synchronize with Writers as well as
Readers.
Defined at line 270 of file ../../zircon/kernel/lib/spsc_buffer/include/lib/spsc_buffer/spsc_buffer.h
Records
Friends
template <AllocatorType Allocator>
class SpscBufferTests