pub struct RingBuffer<T> { /* private fields */ }Expand description
Lock-free single-producer / single-consumer ring buffer backed by a fixed array in shared memory.
T must be Copy so that reads/writes are safe without destructors.
The capacity must be a power of two so that modulo can be done with a mask.
Implementations§
Source§impl<T> RingBuffer<T>where
T: Copy,
impl<T> RingBuffer<T>where
T: Copy,
Sourcepub unsafe fn new(
buffer: *mut T,
write_idx: *mut Atomic<u32>,
read_idx: *mut Atomic<u32>,
capacity: usize,
) -> RingBuffer<T>
pub unsafe fn new( buffer: *mut T, write_idx: *mut Atomic<u32>, read_idx: *mut Atomic<u32>, capacity: usize, ) -> RingBuffer<T>
§Safety
buffer must point to capacity valid, initialized slots.
write_idx and read_idx must point to distinct AtomicU32s.
capacity must be a power of two.
Sourcepub fn push(&self, event: T) -> bool
pub fn push(&self, event: T) -> bool
Attempt to push a single event. Returns true on success, false if
the buffer is full.
pub fn is_empty(&self) -> bool
Trait Implementations§
impl<T> Send for RingBuffer<T>where
T: Send,
impl<T> Sync for RingBuffer<T>where
T: Sync,
Auto Trait Implementations§
impl<T> Freeze for RingBuffer<T>
impl<T> RefUnwindSafe for RingBuffer<T>where
T: RefUnwindSafe,
impl<T> Unpin for RingBuffer<T>
impl<T> UnsafeUnpin for RingBuffer<T>
impl<T> UnwindSafe for RingBuffer<T>where
T: RefUnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more