[][src]Crate spsc_bip_buffer

spsc-bip-buffer is a single-producer single-consumer circular buffer that always supports writing a contiguous chunk of data. Write requests that cannot fit in an available contiguous area will wait till space is newly available (after the consumer has read the data).

spsc-bip-buffer is lock-free and uses atomics for coordination.

Example

use spsc_bip_buffer::bip_buffer_with_len;
let (mut writer, mut reader) = bip_buffer_with_len(256);
let sender = std::thread::spawn(move || {
    for i in 0..128 {
        let mut reservation = writer.spin_reserve(8);
        reservation.copy_from_slice(&[10, 11, 12, 13, 14, 15, 16, i]);
        reservation.send(); // optional, dropping has the same effect
    }
});
let receiver = std::thread::spawn(move || {
    for i in 0..128 {
        while reader.valid().len() < 8 {}
        assert_eq!(&reader.valid()[..8], &[10, 11, 12, 13, 14, 15, 16, i]);
        reader.consume(8);
    }
});
sender.join().unwrap();
receiver.join().unwrap();

Structs

BipBufferReader

Represents the receive side of the single-producer single-consumer circular buffer.

BipBufferWriter

Represents the send side of the single-producer single-consumer circular buffer.

BipBufferWriterReservation

A write reservation returned by reserve or spin_reserve. The sender can access the reserved buffer slice by dererferencing this reservation. Its size is guaranteed to match the requested length in reserve or spin_reserve.

Functions

bip_buffer_from

Creates a new BipBufferWriter/BipBufferReader pair using the provided underlying storage.

bip_buffer_with_len

Creates a new BipBufferWriter/BipBufferReader pair using a Vec of the specified length as underlying storage.