cyclic_pipe
Cyclic Pipe
cyclic_pipe is a Rust library that provides fixed-size, buffer pre-allocated cyclic pipes
which supports multi-producer and multi-consumer concurrent access.
This crate is designed to facilitate efficient and synchronized data transfer between different parts of a program, using a cyclic buffer to manage the data flow.
The cyclic pipe works like a cyclic conveyor belt with fixed number of buckets on it. Producers wait for an empty bucket to put data in, while consumers wait for a bucket with data to take out. Producers put data into the empty bucket and then the bucket is moved to the consumer side. The consumer takes the data out of the bucket and then the empty bucket is moved back to the producer side. The cyclic pipe supports multi-producers and multi-consumers, and ensures that buffer orders are not violated.
Features
- Fixed-size: The size of the pipe is determined at creation time and does not change.
- Pre-allocated buffers: The buffers are allocated once and reused, avoiding the overhead of repeated allocations.
- Synchronized access: Ensures safe concurrent access to the buffer for multi-writter and multi-reader.
- Sequential access: First avaliable buffer will be first written then first transfered to consumer to read.
Usage
Add this to your Cargo.toml:
[]
= "0.1.0"
Import the crate in your code:
extern crate cyclic_pipe;
Example
use thread;
Modules
Builder: To create a cyclic pipe and return producer and consumer ends.Producer: To get empty buffer from pipe and push written data to pipe.Consumer: To get written data and return used buffer to pipe.Token: To access avaliable(writable/readable) buffer.
License
This project is licensed under
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.