Expand description
An implementation of a bounded array-based ring buffer / circular queue that supports a single producer and multiple consumers (SPMC). Individual readers / consumers may get overtaken by the writer / producer without either of them blocking. Readers can detect when new data is available, when the queue is empty, and when they have been overtaken. Readers may also skip to the front of the queue.
Currently, hang-ups are not detected. Additionally, the stored value needs
to implement Copy
and Default
.
To use a ring buffer, call ring_buffer to receive a Reader and a Writer. Call Writer::write to push new data onto the queue and Reader::read to receive the new data. Pass both readers and writer to different threads and clone new readers as desired.
Structs§
- Reader
- The receiving end of a ring buffer, which reads data from the Writer that it was created with by calling ring_buffer. Call Reader::read to receive new data if it’s, available, and clone the reader to create additional readers.
- Writer
- The sending end of a ring buffer, which passes data to any Reader instances created from calling ring_buffer. Call Writer::write to make new data available, at risk of overwriting old data and overtaking readers.
Enums§
- Read
Result - The result of reading from a ring buffer by Reader::read
Functions§
- ring_
buffer - Construct a new ring buffer consisting of a Reader and a Writer. The internal buffer will have the specified capacity, and no additional heap allocation will be performed by either the readers or the writer. A larger capacity means that more past data will be retained before being overwritten, and slower readers will have a better chance of observing all data, though it also increases memory usage.