Coverage Report

Created: 2021-01-22 16:54

src/lib.rs
Line
Count
Source
1
1
//! Tools for concurrent programming.//! 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(
49
    missing_docs,
50
    missing_debug_implementations,
51
    rust_2018_idioms,
52
    unreachable_pub
53
)]
54
#![cfg_attr(not(feature = "std"), no_std)]
55
#![cfg_attr(feature = "nightly", feature(cfg_target_has_atomic))]
56
// matches! requires Rust 1.42
57
#![allow(clippy::match_like_matches_macro)]
58
59
#[cfg_attr(feature = "nightly", cfg(target_has_atomic = "ptr"))]
60
pub use crossbeam_utils::atomic;
61
62
pub mod utils {
63
    //! Miscellaneous utilities.
64
    //!
65
    //! * [`Backoff`], for exponential backoff in spin loops.
66
    //! * [`CachePadded`], for padding and aligning a value to the length of a cache line.
67
68
    pub use crossbeam_utils::Backoff;
69
    pub use crossbeam_utils::CachePadded;
70
}
71
72
use cfg_if::cfg_if;
73
74
cfg_if! {
75
    if #[cfg(feature = "alloc")] {
76
        #[doc(inline)]
77
        pub use crossbeam_epoch as epoch;
78
79
        #[doc(inline)]
80
        pub use crossbeam_queue as queue;
81
    }
82
}
83
84
cfg_if! {
85
    if #[cfg(feature = "std")] {
86
        #[doc(inline)]
87
        pub use crossbeam_deque as deque;
88
89
        #[doc(inline)]
90
        pub use crossbeam_channel as channel;
91
        pub use crossbeam_channel::select;
92
93
        pub use crossbeam_utils::sync;
94
95
        #[cfg(not(loom_crossbeam))]
96
        pub use crossbeam_utils::thread;
97
        #[cfg(not(loom_crossbeam))]
98
        pub use crossbeam_utils::thread::scope;
99
    }
100
}