Skip to main content

scatto/
lib.rs

1//! low-latency inter-thread communication inspired by lmax disruptor.
2//!
3//! this crate provides zero-copy, lock-free channels for high-performance
4//! applications.
5//!
6//! # features
7//!
8//! - pre-allocated ring buffers (no allocation in hot path)
9//! - sequence-based coordination (no locks)
10//! - multiple wait strategies for latency/CPU trade-offs
11//! - zero-copy in-place mutation support
12//! - cache-line padding to prevent false sharing
13//!
14//! # channel types
15//!
16//! - [`spsc`]: single producer single consumer - lowest latency
17//! - [`mpsc`]: multi producer single consumer - multiple senders
18//!
19//! # example
20//!
21//! ```ignore
22//! use scatto::spsc;
23//!
24//! // create channel with 1024-slot buffer
25//! let (mut producer, mut consumer) = spsc::channel::<u64>(1024);
26//!
27//! // producer thread
28//! std::thread::spawn(move || {
29//!     for i in 0..1000 {
30//!         producer.send(i).unwrap();
31//!     }
32//! });
33//!
34//! // consumer
35//! for _ in 0..1000 {
36//!     let value = consumer.recv().unwrap();
37//! }
38//! ```
39
40#![warn(missing_docs)]
41#![warn(rust_2018_idioms)]
42
43pub mod barrier;
44pub mod error;
45pub mod mpsc;
46pub mod ringbuffer;
47pub mod spsc;
48
49pub(crate) mod common;
50
51pub use error::{RecvError, SendError, TryRecvError, TrySendError};
52pub use cpu::{CachePadded, Cursor, CACHE_LINE_SIZE, INITIAL_CURSOR_VALUE};
53pub use ringbuffer::RingBuffer;
54
55pub use cpu::{
56    wait_strategy, BackoffWait, BusySpinWait, SpinLoopHintWait, WaitStrategy, YieldingWait,
57};
58
59// re-export fence helpers for architecture-aware memory ordering
60pub use cpu::{
61    cpu_pause, fence_acq_rel, fence_acquire, fence_release,
62};