|
CHERIoT RTOS
A compartmentalised RTOS for CHERIoT hardware
|
A simple single-producer, single-consumer ring buffer that can be made multi-producer and / or multi-consumer by adding locking. More...
#include <ring_buffer.hh>
Public Member Functions | |
| void | push (Message &&message) |
| Push an element into the ring. | |
| Message | pop () |
| Pop the next message from the queue. | |
A simple single-producer, single-consumer ring buffer that can be made multi-producer and / or multi-consumer by adding locking.
The first two template parameters are the type of the message and the size of the buffer (in messages). The next template arguments are the locks to use for protecting the producer and consumer ends.
In the uncontended (or single-producer, single-consumer) case where the producer and consumer are balanced and the ring is neither full nor empty, this will not use any cross-compartment calls. When the queue is full, producers will block on a futex. When the queue is empty, consumers will block on a futex. On transitions to non-empty and non-full, the queue will issue a futex_wake cross-compartment call. If locks are used, they may introduce additional cross-compartment calls.
Note: The size must be a power of two.
Definition at line 29 of file ring_buffer.hh.
|
inline |
Pop the next message from the queue.
Definition at line 107 of file ring_buffer.hh.
|
inline |
Push an element into the ring.
The caller is responsible for ensuring that, if this contains pointers, they have the global permission and so the move operation will not fault.
Definition at line 83 of file ring_buffer.hh.