Struct triple_buffer::Output
source · [−]pub struct Output<T: Send> { /* private fields */ }
Expand description
Consumer interface to the triple buffer
The consumer of data can use this struct to access the latest published update from the producer whenever he likes. Readout is nonblocking: a collision between the producer and consumer will result in cache contention, but deadlocks and scheduling-induced slowdowns cannot happen.
Implementations
sourceimpl<T: Send> Output<T>
impl<T: Send> Output<T>
sourcepub fn updated(&self) -> bool
pub fn updated(&self) -> bool
Tell whether a buffer update is incoming from the producer
This method is only intended for diagnostics purposes. Please do not let it inform your decision of reading a value or not, as that would effectively be building a very poor spinlock-based double buffer implementation. If what you truly need is a double buffer, build yourself a proper blocking one instead of wasting CPU time.
sourcepub fn output_buffer(&mut self) -> &mut T
pub fn output_buffer(&mut self) -> &mut T
Access the output buffer directly
This advanced interface allows you to modify the contents of the output buffer, so that you can avoid copying the output value when this is an expensive process. One possible application, for example, is to post-process values from the producer before use.
However, by using it, you force yourself to take into account some implementation subtleties that you could normally ignore.
First, keep in mind that you can lose access to the current output
buffer any time read()
or update()
is called, as it may be replaced
by an updated buffer from the producer automatically.
Second, to reduce the potential for the aforementioned usage error, this
method does not update the output buffer automatically. You need to call
update()
in order to fetch buffer updates from the producer.
sourcepub fn update(&mut self) -> bool
pub fn update(&mut self) -> bool
Update the output buffer
Check if the producer submitted a new data version, and if one is available, update our output buffer to use it. Return a flag that tells you whether such an update was carried out.
Bear in mind that when this happens, you will lose any change that you
performed to the output buffer via the output_buffer()
interface.