Expand description
Provides strategies used by handles when waiting for sequences on the ring buffer.
Also provided are three traits for implementing your own wait logic.
§Performance
Each strategy provides a tradeoff between latency and CPU use, as detailed in their separate docs, but this is not the only aspect to consider when optimizing performance. The size of the strategy is also an important factor.
Each handle struct includes a wait strategy. So the size of the strategy may impact performance if, for example, that additional size prevents the handle from fitting into a single cache line.
Cache lines are commonly 64, or 128 bytes.
When the wait strategy is zero-sized, each handle has the following size (in bytes, on a 64-bit system). Changes in these sizes, if compiled for a single system, are considered breaking.
| Handle | size |
|---|---|
Consumer | 40 |
Producer | 40 |
MultiProducer | 48 |
And here are the minimum sizes of the provided strategies (on a 64-bit system), assuming
size_of::<W>() == 0. Changes in these sizes are also considered breaking.
| Strategy | size |
|---|---|
WaitBusy | 0 |
WaitBusyHint | 0 |
WaitYield | 0 |
WaitSleep | 8 |
WaitPhased<W> | 16 |
Timeout<W> | 8 |
Various provided strategies are limited to wait durations of u64::MAX nanoseconds, which is
done in order to keep their sizes small. Storing a Duration instead would double the
minimum size of these strategies.
use std::time::Duration;
assert_eq!(size_of::<Duration>(), 16);
assert_eq!(size_of::<u64>(), 8);Structs§
- Timed
Out - Indicates that the waiting handle has timed out.
- Timeout
- Wrapper which provides timeout capabilities to strategies implementing
Waiting. - Wait
Busy - Pure busy-spin waiting.
- Wait
Busy Hint - Busy-wait and signal that a spin loop is occurring.
- Wait
Phased - Performs a phased back-off of strategies during the wait loop.
- Wait
Sleep - Sleep the current thread on each iteration of the wait loop.
- Wait
Yield - Busy-wait, but allow the current thread to yield to the OS.
Traits§
- TryWait
Strategy - Implement to provide a fallible wait loop which runs as a handle waits for a sequence.
- Wait
Strategy - Implement to provide a wait loop which runs as a handle waits for a sequence.
- Waiting
- Implement to provide logic which will run inside a wait loop.