Expand description
§triple_buf_64
A cheap realtime-safe lock-free triple buffer data structure that stores 64 bits of data
On platforms which natively support 64 bit atomics, this is implemented with
a single cheap AtomicU64 load/store operation
(this can optionally use portable_atomic
for maximum compatibility).
On platforms which do NOT natively support 64 bit atomics, this is implemented using a more expensive triple buffer implementation (using triple_buffer).
This can be useful when you want to pass a small amount of data between realtime threads (i.e. audio threads) very cheaply on most platforms, but also have a realtime-safe fallback for platforms which do not have 64 bit atomics (i.e. PowerPC).
This crate is no_std compatible and is implemented with zero unsafe code.
§Data Types
This triple buffer accepts any data type that implements the Data64Bit
trait. Implementations for the following primitives are provided:
§Example
// Construct an input/output pair with the given 64 bit type.
let (mut input, mut output) = triple_buffer_64::<i64>(-3);
// The output will read the initial value.
assert_eq!(output.read(), -3);
assert_eq!(output.read(), -3);
// Write new data into the buffer.
input.write(-9845);
assert_eq!(output.read(), -9845);
assert_eq!(output.read(), -9845);
input.write(69);
input.write(68);
input.write(67);
// The output always reads the latest value that was pushed to the buffer.
assert_eq!(output.read(), 67);
assert_eq!(output.read(), 67);Structs§
- Input64
- The producer end of a simple realtime-safe lock-free triple buffer type that stores 64 bits of data.
- Output64
- The consumer end of a simple realtime-safe lock-free triple buffer type that stores 64 bits of data.
Traits§
- Data64
Bit - A 64 bit data type that is used in realtime-safe lock-free triple buffer.
Functions§
- is_
atomic - Returns
trueiftriple_buffer_64will use atomics, orfalseif it will fall back to using a triple buffer. - triple_
buffer_ 64 - Create a new realtime-safe lock-free triple buffer type that stores 64 bits of data.