pub struct NotificationRing { /* private fields */ }Expand description
Lock-free SPSC ring buffer carrying NotificationRef from Ring 0 to Ring 1.
Pre-allocates a power-of-2 sized buffer of NotificationRef slots so that
the hot-path push never allocates. Uses UnsafeCell for interior mutability
with the SPSC invariant: single writer (Ring 0), single reader (Ring 1).
§Capacity
The capacity is always rounded up to the next power of two. This allows
fast index computation via bitmask (pos & mask) instead of modulo.
Implementations§
Source§impl NotificationRing
impl NotificationRing
Sourcepub fn new(capacity: usize) -> Self
pub fn new(capacity: usize) -> Self
Creates a new notification ring with the given capacity.
The capacity is rounded up to the next power of two. Minimum effective capacity is 2.
Sourcepub fn push(&self, notif: NotificationRef) -> bool
pub fn push(&self, notif: NotificationRef) -> bool
Pushes a notification into the ring (Ring 0 writer).
Returns true on success, false if the ring is full (backpressure).
Zero allocations on the hot path.
Sourcepub fn pop(&self) -> Option<NotificationRef>
pub fn pop(&self) -> Option<NotificationRef>
Pops a notification from the ring (Ring 1 reader).
Returns None if the ring is empty.
Sourcepub fn drain_into<F: FnMut(NotificationRef)>(&self, f: F) -> usize
pub fn drain_into<F: FnMut(NotificationRef)>(&self, f: F) -> usize
Drains all pending notifications, calling f for each one.
Returns the number of notifications drained.
Trait Implementations§
impl Send for NotificationRing
impl Sync for NotificationRing
Auto Trait Implementations§
impl !Freeze for NotificationRing
impl !RefUnwindSafe for NotificationRing
impl Unpin for NotificationRing
impl UnwindSafe for NotificationRing
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.