| alias.rs |
|
1065 |
- |
| benchmarks |
|
|
- |
| lib.rs |
Lock-free SPSC FIFO ring buffer with direct access to inner data.
# Usage
At first you need to create the ring buffer itself. [`HeapRb`] is recommended but you may [choose another one](#types).
After the ring buffer is created it may be splitted into pair of [`Producer`](`traits::Producer`) and [`Consumer`](`traits::Consumer`).
Producer is used to insert items to the ring buffer, consumer - to remove items from it.
# Types
There are several types of ring buffers provided:
+ [`LocalRb`]. Only for single-threaded use.
+ [`SharedRb`]. Can be shared between threads. Its frequently used instances:
+ [`HeapRb`]. Contents are stored in dynamic memory. *Recommended for use in most cases.*
+ [`StaticRb`]. Contents can be stored in statically-allocated memory.
You may also provide your own generic parameters.
# Performance
[`SharedRb`] needs to synchronize CPU cache between CPU cores. This synchronization has some overhead.
To avoid multiple unnecessary synchronizations you may use methods that operate many items at once
([`push_slice`](`traits::Producer::push_slice`)/[`push_iter`](`traits::Producer::push_iter`), [`pop_slice`](`traits::Consumer::pop_slice`), etc.).
Caching endpoints also avoid repeatedly fetching the opposite endpoint's index when progress is possible.
All completed operations publish their index updates immediately, including each step of [`pop_iter`](`traits::Consumer::pop_iter`).
The former frozen endpoints are deprecated compatibility wrappers; see [`wrap::frozen`] for migration details.
[`skip`](`traits::Consumer::skip`) and [`clear`](`traits::Consumer::clear`) take constant time for items without destructors.
Items that need destruction are dropped individually, with each slot kept occupied until its destructor finishes.
For single-threaded usage [`LocalRb`] is recommended because it is slightly faster than [`SharedRb`] due to absence of CPU cache synchronization.
# Examples
|
6477 |
- |
| rb |
|
|
- |
| storage.rs |
|
6329 |
- |
| tests |
|
|
- |
| traits |
|
|
- |
| transfer.rs |
|
1149 |
- |
| utils.rs |
|
2181 |
- |
| wrap |
|
|
- |