crossbeam/
lib.rs

1//! Tools for concurrent programming.
2//!
3//! ## Atomics
4//!
5//! * [`AtomicCell`], a thread-safe mutable memory location.
6//! * [`AtomicConsume`], for reading from primitive atomic types with "consume" ordering.
7//!
8//! ## Data structures
9//!
10//! * [`deque`], work-stealing deques for building task schedulers.
11//! * [`ArrayQueue`], a bounded MPMC queue that allocates a fixed-capacity buffer on construction.
12//! * [`SegQueue`], an unbounded MPMC queue that allocates small buffers, segments, on demand.
13//!
14//! ## Memory management
15//!
16//! * [`epoch`], an epoch-based garbage collector.
17//!
18//! ## Thread synchronization
19//!
20//! * [`channel`], multi-producer multi-consumer channels for message passing.
21//! * [`Parker`], a thread parking primitive.
22//! * [`ShardedLock`], a sharded reader-writer lock with fast concurrent reads.
23//! * [`WaitGroup`], for synchronizing the beginning or end of some computation.
24//!
25//! ## Utilities
26//!
27//! * [`Backoff`], for exponential backoff in spin loops.
28//! * [`CachePadded`], for padding and aligning a value to the length of a cache line.
29//! * [`scope`], for spawning threads that borrow local variables from the stack.
30//!
31//! [`AtomicCell`]: atomic::AtomicCell
32//! [`AtomicConsume`]: atomic::AtomicConsume
33//! [`ArrayQueue`]: queue::ArrayQueue
34//! [`SegQueue`]: queue::SegQueue
35//! [`Parker`]: sync::Parker
36//! [`ShardedLock`]: sync::ShardedLock
37//! [`WaitGroup`]: sync::WaitGroup
38//! [`Backoff`]: utils::Backoff
39//! [`CachePadded`]: utils::CachePadded
40
41#![doc(test(
42    no_crate_inject,
43    attr(
44        deny(warnings, rust_2018_idioms),
45        allow(dead_code, unused_assignments, unused_variables)
46    )
47))]
48#![warn(missing_docs, missing_debug_implementations, rust_2018_idioms)]
49#![cfg_attr(not(feature = "std"), no_std)]
50#![cfg_attr(feature = "nightly", feature(cfg_target_has_atomic))]
51// matches! requires Rust 1.42
52#![allow(clippy::match_like_matches_macro)]
53
54#[cfg_attr(feature = "nightly", cfg(target_has_atomic = "ptr"))]
55pub use crossbeam_utils::atomic;
56
57/// Miscellaneous utilities.
58pub mod utils {
59    pub use crossbeam_utils::Backoff;
60    pub use crossbeam_utils::CachePadded;
61}
62
63use cfg_if::cfg_if;
64
65cfg_if! {
66    if #[cfg(feature = "alloc")] {
67        mod _epoch {
68            pub use crossbeam_epoch;
69        }
70        #[doc(inline)]
71        pub use crate::_epoch::crossbeam_epoch as epoch;
72
73        mod _queue {
74            pub use crossbeam_queue;
75        }
76        #[doc(inline)]
77        pub use crate::_queue::crossbeam_queue as queue;
78    }
79}
80
81cfg_if! {
82    if #[cfg(feature = "std")] {
83        mod _deque {
84            pub use crossbeam_deque;
85        }
86        #[doc(inline)]
87        pub use crate::_deque::crossbeam_deque as deque;
88
89        mod _channel {
90            pub use crossbeam_channel;
91        }
92        #[doc(inline)]
93        pub use crate::_channel::crossbeam_channel as channel;
94
95        pub use crossbeam_channel::select;
96
97        pub use crossbeam_utils::sync;
98        pub use crossbeam_utils::thread;
99        pub use crossbeam_utils::thread::scope;
100    }
101}