pub struct ReorderingReceiver<'a> { /* private fields */ }Expand description
Ergonomic exact-delivery wrapper: pairs a stamped-ring consumer
handle (PinnedRing) with a ReorderBuffer so a GlobalFifo
(MergeByStamp) consumer receives items in exact stamp order without
the MergeStrict watermark coupling or a Vyukov second CAS.
let pin = ring.pin_current_shape();
let mut rx = ReorderingReceiver::new(&pin, 0);
let mut out = [0u8; 56];
// steady state:
while let Some((len, stamp)) = rx.try_recv(&mut out) {
deliver(&out[..len], stamp);
}
// end of stream - drain the buffered tail in order:
while let Some((len, stamp)) = rx.flush(&mut out) {
deliver(&out[..len], stamp);
}Implementations§
Source§impl<'a> ReorderingReceiver<'a>
impl<'a> ReorderingReceiver<'a>
Sourcepub fn new(pin: &'a PinnedRing<'a>, consumer_id: usize) -> Self
pub fn new(pin: &'a PinnedRing<'a>, consumer_id: usize) -> Self
Wrap pin (a stamped-ring consumer handle) with the default
adaptive window.
Sourcepub fn with_window(
pin: &'a PinnedRing<'a>,
consumer_id: usize,
floor: usize,
cap: usize,
) -> Self
pub fn with_window( pin: &'a PinnedRing<'a>, consumer_id: usize, floor: usize, cap: usize, ) -> Self
Wrap pin with an explicit floor/cap window (see
ReorderBuffer::with_window).
Sourcepub fn try_recv(&mut self, out: &mut [u8]) -> Option<(usize, u64)>
pub fn try_recv(&mut self, out: &mut [u8]) -> Option<(usize, u64)>
Pop one item from the ring into the buffer (if available), then
release the next in-order item once the window is full. Returns
(payload_len, stamp), or None while the window is still
filling or the ring is momentarily empty. On end of stream,
finish with flush.
Sourcepub fn flush(&mut self, out: &mut [u8]) -> Option<(usize, u64)>
pub fn flush(&mut self, out: &mut [u8]) -> Option<(usize, u64)>
Drain the buffered tail in stamp order. Call in a loop after the
producers have finished to release the last window items.
Sourcepub fn corrections(&self) -> u64
pub fn corrections(&self) -> u64
Times the adaptive window had to grow (see
ReorderBuffer::corrections).