Struct triple_buffer::Input [−][src]
pub struct Input<T: Send> { /* fields omitted */ }
Expand description
Producer interface to the triple buffer
The producer of data can use this struct to submit updates to the triple buffer whenever he likes. These updates are nonblocking: a collision between the producer and the consumer will result in cache contention, but deadlocks and scheduling-induced slowdowns cannot happen.
Implementations
Check if the consumer has fetched our last submission yet
This method is only intended for diagnostics purposes. Please do not let it inform your decision of sending or not sending a value, 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.
Access the input buffer directly
This advanced interface allows you to update the input buffer in place, so that you can avoid creating values of type T repeatedy just to push them into the triple buffer when doing so is expensive.
However, by using it, you force yourself to take into account some implementation subtleties that you could normally ignore.
First, the buffer does not contain the last value that you published (which is now available to the consumer thread). In fact, what you get may not match any value that you sent in the past, but rather be a new value that was written in there by the consumer thread. All you can safely assume is that the buffer contains a valid value of type T, which you may need to “clean up” before use using a type-specific process.
Second, we do not send updates automatically. You need to call
publish()
in order to propagate a buffer update to the consumer.
Alternative designs based on Drop were considered, but considered too
magical for the target audience of this interface.
Publish the current input buffer, checking for overwrites
After updating the input buffer using input_buffer()
, you can use this
method to publish your updates to the consumer.
This will replace the current input buffer with another one, as you cannot continue using the old one while the consumer is accessing it.
It will also tell you whether you overwrote a value which was not read by the consumer thread.