Skip to main content

BatchReader

Trait BatchReader 

Source
pub unsafe trait BatchReader {
    type Item;

    // Required methods
    fn read_buffer(&mut self) -> &[Self::Item];
    unsafe fn advance(&mut self, n: usize);

    // Provided method
    unsafe fn release(&mut self) { ... }
}
Expand description

Trait for queue receivers that support batch read operations.

§Safety

Implementations must ensure:

  • read_buffer returns a valid slice of initialized items that remain valid until advance is called
  • advance publishes the new head to the producer (atomic store + wake)
  • release releases any held resources (e.g., shard locks), and is a no-op when no resources are held

§Ownership

Items are returned by shared reference — ownership is not transferred to the caller. advance makes slots reusable by the producer but does not drop the previous values. For types that implement Drop, use ReadGuard::drain_into or the ReadGuard iterator to take ownership; plain ReadGuard::as_slice combined with ReadGuard::advance will skip the items’ destructors.

Required Associated Types§

Required Methods§

Source

fn read_buffer(&mut self) -> &[Self::Item]

Returns a slice of available contiguous items.

Items are returned by shared reference — ownership is not transferred. See the trait-level ownership note.

Source

unsafe fn advance(&mut self, n: usize)

Advance head by n and publish to the producer (atomic store + wake).

Does not drop the items being advanced past. The producer may immediately overwrite those slots.

§Safety

n must not exceed available unconsumed items.

Provided Methods§

Source

unsafe fn release(&mut self)

Release held resources (e.g., shard lock).

Default is a no-op for queue types that don’t hold resources.

§Safety

Must only be called after all consumed items have been advanced past via advance.

Implementors§

Source§

impl<T> BatchReader for gil::mpmc::sharded::Receiver<T>

§Safety

The implementation locks a shard spinlock in read_buffer and releases it in release. Between these two calls, no other receiver can access the locked shard.

Items are returned by shared reference — ownership is not transferred. See BatchReader for details.

Source§

type Item = T

Source§

impl<T> BatchReader for gil::mpsc::sharded::Receiver<T>

§Safety

The implementation delegates to the per-shard SPSC receivers. read_buffer polls shards round-robin and returns the first non-empty contiguous slice. advance publishes the new head on the active shard.

Items are returned by shared reference — ownership is not transferred. See BatchReader for details.

Source§

type Item = T

Source§

impl<T> BatchReader for gil::mpsc::sharded_parking::Receiver<T>

§Safety

The implementation delegates to per-shard SPSC QueuePtrs. read_buffer polls shards round-robin and returns the first non-empty contiguous slice. advance publishes the new head and wakes parked senders.

Source§

type Item = T

Source§

impl<T> BatchReader for gil::spmc::sharded::Receiver<T>

§Safety

The implementation delegates to the single shard’s SPSC QueuePtr.

Source§

type Item = T

Source§

impl<T> BatchReader for gil::spmc::sharded_parking::Receiver<T>

§Safety

The implementation delegates to the single shard’s SPSC QueuePtr.

Source§

type Item = T

Source§

impl<T> BatchReader for gil::spsc::parking::Receiver<T>

§Safety

The implementation delegates to the queue’s atomic head/tail for synchronisation. read_buffer refreshes the cached tail and returns a contiguous slice from the ring buffer. advance publishes the new head via a Release store and wakes the sender via futex.

Source§

type Item = T

Source§

impl<T> BatchReader for gil::spsc::Receiver<T>

§Safety

The implementation delegates to the queue’s atomic head/tail for synchronisation. read_buffer refreshes the cached tail and returns a contiguous slice from the ring buffer. advance publishes the new head via a Release store and wakes the sender when the async feature is enabled.

Source§

type Item = T