| Crates.io | vmcircbuffer |
| lib.rs | vmcircbuffer |
| version | 0.0.10 |
| created_at | 2021-09-18 18:43:36.235035+00 |
| updated_at | 2023-09-01 07:36:50.161807+00 |
| description | Double Mapped Circular Buffer |
| homepage | https://www.futuresdr.org |
| repository | https://github.com/futuresdr/vmcircbuffer/ |
| max_upload_size | |
| id | 453384 |
| size | 96,022 |
Notifiers to ease integration.DoubleMappedBuffer) is exported to allow custom implementations.This circular buffer implementation maps the underlying buffer twice, back-to-back into the virtual address space of the process. This arrangement allows the circular buffer to present the available data sequentially, (i.e., as a slice) without having to worry about wrapping.
use vmcircbuffer::sync;
let mut w = sync::Circular::new::<u32>()?;
let mut r = w.add_reader();
// delay producing by 1 sec
let now = std::time::Instant::now();
let delay = std::time::Duration::from_millis(1000);
// producer thread
std::thread::spawn(move || {
std::thread::sleep(delay);
let w_buff = w.slice();
for v in w_buff.iter_mut() {
*v = 23;
}
let l = w_buff.len();
w.produce(l);
});
// blocks until data becomes available
let r_buff = r.slice().unwrap();
assert!(now.elapsed() > delay);
for v in r_buff {
assert_eq!(*v, 23);
}
let l = r_buff.len();
r.consume(l);
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the project, shall be licensed as Apache 2.0, without any additional terms or conditions.