1
2
3
4
5
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//! This is a fork of the [`ringbuf`] crate that uses [`basedrop`]'s `Shared` pointer in place of `Arc`. This ensures that when all references to the ring buffer are dropped, the underlying `Vec` will never potentially get deallocated (a non-realtime safe operation) in the realtime thread. Instead, all allocations are cleaned up in whatever thread owns the basedrop `Collector` object.
//!
//! This is especially useful for audio applications.
//!
//! [`ringbuf`]: https://github.com/agerasev/ringbuf
//! [`basedrop`]: https://github.com/glowcoil/basedrop
//!
//! --------------------------------------------------------------
//!
//! Lock-free single-producer single-consumer (SPSC) FIFO ring buffer with direct access to inner data.
//!
//! # Overview
//!
//! `RingBuffer` is the initial structure representing ring buffer itself.
//! Ring buffer can be splitted into pair of `Producer` and `Consumer`.
//!
//! `Producer` and `Consumer` are used to append/remove elements to/from the ring buffer accordingly. They can be safely sent between threads.
//! Operations with `Producer` and `Consumer` are lock-free - they succeed or fail immediately without blocking or waiting.
//!
//! Elements can be effectively appended/removed one by one or many at once.
//! Also data could be loaded/stored directly into/from [`Read`]/[`Write`] instances.
//! And finally, there are `unsafe` methods allowing thread-safe direct access in place to the inner memory being appended/removed.
//!
//! [`Read`]: https://doc.rust-lang.org/std/io/trait.Read.html
//! [`Write`]: https://doc.rust-lang.org/std/io/trait.Write.html
//!
//! When building with nightly toolchain it is possible to run benchmarks via `cargo bench --features benchmark`.
//!
//! # Examples
//!
//! ## Simple example
//!
//! ```rust
//! # extern crate ringbuf_basedrop;
//! use ringbuf_basedrop::RingBuffer;
//! use basedrop::Collector;
//! # fn main() {
//! let collector = Collector::new();
//!
//! let rb = RingBuffer::<i32>::new(2);
//! let (mut prod, mut cons) = rb.split(&collector.handle());
//!
//! prod.push(0).unwrap();
//! prod.push(1).unwrap();
//! assert_eq!(prod.push(2), Err(2));
//!
//! assert_eq!(cons.pop().unwrap(), 0);
//!
//! prod.push(2).unwrap();
//!
//! assert_eq!(cons.pop().unwrap(), 1);
//! assert_eq!(cons.pop().unwrap(), 2);
//! assert_eq!(cons.pop(), None);
//! # }
//! ```
extern crate alloc;
extern crate std;
extern crate test;
pub use *;
pub use *;
pub use *;