Coder Social home page Coder Social logo

rtrb's Introduction

Real-Time Ring Buffer

A wait-free single-producer single-consumer (SPSC) ring buffer for Rust.

This crate can be used without the standard library (#![no_std]) by disabling the std feature (which is enabled by default), but the alloc crate is needed nevertheless.

Usage

Add this to your Cargo.toml:

[dependencies]
rtrb = "0.2"

Breaking Changes

For a list of breaking changes and for instructions how to upgrade between released versions, have a look at the changelog.

Development

Running the tests:

cargo test

Testing the benchmarks (without actually benchmarking):

cargo test --benches

Running the benchmarks (using the criterion crate; results will be available in target/criterion/report/index.html):

cargo bench

Creating the HTML docs (which will be available in target/doc/rtrb/index.html):

cargo doc

To measure code coverage, nightly Rust is required, as well as a few additional dependencies:

rustup toolchain install nightly
rustup component add llvm-tools-preview
cargo install grcov

Test coverage data can be obtained and analyzed with these commands:

cargo clean
RUSTFLAGS="-Z instrument-coverage" RUSTDOCFLAGS="-Z instrument-coverage -Z unstable-options --persist-doctests target/debug/doctestbins" LLVM_PROFILE_FILE="coverage/%p-%m.profraw" cargo +nightly test
grcov coverage --source-dir . --binary-path target/debug --output-type html --output-path coverage

The last command creates an HTML report in coverage/index.html.

Testing with Miri also needs nightly Rust:

cargo +nightly miri test

Running the tests with ThreadSanitizer requires nightly Rust as well:

RUSTFLAGS="-Z sanitizer=thread" cargo +nightly test --tests -Z build-std --target x86_64-unknown-linux-gnu

You might have to adapt the --target option to your system (see e.g. rustup show).

Minimum Supported rustc Version

This crate's minimum supported rustc version (MSRV) is 1.36.0. The MSRV is not expected to be updated frequently, but if it is, there will be (at least) a minor version bump.

Origin Story

The initial code has been ripped off of crossbeam-rs/crossbeam#338, with permission of the PR author.

It has been isolated from the rest of crossbeam with git-filter-repo:

git-filter-repo --subdirectory-filter crossbeam-queue --path src/spsc.rs --path tests/spsc.rs --refs refs/heads/spsc

Alternatives

If you don't like this crate, no problem, there are several alternatives for you to choose from. There are many varieties of ring buffers available, here we limit the selection to wait-free SPSC implementations:

  • fixed-queue (using const generics, see fixed_queue::spsc)
  • heapless (for embedded systems, see heapless::spsc)
  • jack (FFI bindings for JACK, see jack::Ringbuffer)
  • magnetic (see magnetic::spsc module)
  • npnc (see npnc::bounded::spsc module)
  • ringbuf (supports const generics and heap allocation)
  • ringbuffer-spsc (using const generics)
  • shmem-ipc (see shmem_ipc::sharedring and shmem_ipc::ringbuf modules)

There are also implementations in other languages:

If you know more alternatives for this list, please open an issue.

License

Licensed under either of

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.

rtrb's People

Contributors

diwic avatar mgeier avatar ramtype0 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.