ringbuffer_spsc

Struct RingBuffer

Source
pub struct RingBuffer<T, const N: usize> { /* private fields */ }

Implementations§

Source§

impl<T, const N: usize> RingBuffer<T, N>

Source

pub fn new() -> (RingBufferWriter<T, N>, RingBufferReader<T, N>)

👎Deprecated since 0.1.8: please use init() instead.
Source

pub fn init() -> (RingBufferWriter<T, N>, RingBufferReader<T, N>)

Examples found in repository?
examples/throughput.rs (line 7)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
fn main() {
    let (mut tx, mut rx) = RingBuffer::<usize, 16>::init();
    let counter = Arc::new(AtomicUsize::new(0));

    std::thread::spawn(move || {
        let mut current: usize = 0;
        loop {
            if tx.push(current).is_none() {
                current = current.wrapping_add(1);
            } else {
                std::thread::yield_now();
            }
        }
    });

    let c_counter = counter.clone();
    std::thread::spawn(move || {
        let mut current: usize = 0;
        loop {
            if let Some(c) = rx.pull() {
                assert_eq!(c, current);
                current = current.wrapping_add(1);
                c_counter.fetch_add(1, Ordering::Relaxed);
            } else {
                std::thread::yield_now();
            }
        }
    });

    loop {
        std::thread::sleep(Duration::from_secs(1));
        println!("{} elem/s", counter.swap(0, Ordering::Relaxed));
    }
}

Trait Implementations§

Source§

impl<T, const N: usize> Drop for RingBuffer<T, N>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T, const N: usize> Send for RingBuffer<T, N>

Source§

impl<T, const N: usize> Sync for RingBuffer<T, N>

Auto Trait Implementations§

§

impl<T, const N: usize> !Freeze for RingBuffer<T, N>

§

impl<T, const N: usize> !RefUnwindSafe for RingBuffer<T, N>

§

impl<T, const N: usize> Unpin for RingBuffer<T, N>
where T: Unpin,

§

impl<T, const N: usize> UnwindSafe for RingBuffer<T, N>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.