disk_ringbuffer/lib.rs
1/*!
2
3# On-Disk Ringbuffer
4
5This is an extremely simple implementation of an on-disk broadcast channel that
6sort of pretends to be a ringbuffer! It uses memory-mapped pages to have interprocess,
7lock-free, reads and writes. It's blazingly fast, but tends to hog disk-space for better
8efficiency (fewer but bigger memory-mapped pages).
9
10
11## Example
12```rust
13use disk_ringbuffer::ringbuf;
14
15fn example() {
16 // takes directory to use as ringbuf storage and the total number of pages to store as input.
17 // note that each page takes 80Mb and setting the max_pages to zero implies an unbounded queue
18 let (mut tx, mut rx) = ringbuf::new("test-example").unwrap();
19 ringbuf::set_max_qpage("text-example", 2).unwrap();
20
21 // you can clone readers and writers to use in other threads!
22 let tx2 = tx.clone();
23
24 for i in 0..500_000 {
25 tx.push(i.to_string());
26 }
27
28 for i in 0..500_000 {
29 let m = rx.pop().unwrap().unwrap();
30 assert_eq!(m, i.to_string());
31 }
32}
33```
34
35senders are also completely thread safe!
36```rust
37use disk_ringbuffer::ringbuf::new;
38
39fn thread_example() {
40
41 let (mut tx, mut rx) = new("test-thread-example").unwrap();
42 let mut tx2 = tx.clone();
43
44 let t = std::thread::spawn(move || {
45 for i in 0..500_000 {
46 tx.push(i.to_string()).unwrap();
47 }
48 });
49
50 tx2.push("asdf").unwrap();
51
52 t.join().unwrap();
53}
54```
55*/
56
57mod qpage;
58pub mod ringbuf;