Module wait

Module wait 

Source
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.

Handlesize
Consumer40
Producer40
MultiProducer48

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.

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§

TimedOut
Indicates that the waiting handle has timed out.
Timeout
Wrapper which provides timeout capabilities to strategies implementing Waiting.
WaitBusy
Pure busy-spin waiting.
WaitBusyHint
Busy-wait and signal that a spin loop is occurring.
WaitPhased
Performs a phased back-off of strategies during the wait loop.
WaitSleep
Sleep the current thread on each iteration of the wait loop.
WaitYield
Busy-wait, but allow the current thread to yield to the OS.

Traits§

TryWaitStrategy
Implement to provide a fallible wait loop which runs as a handle waits for a sequence.
WaitStrategy
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.