1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#![cfg_attr(feature = "nightly", feature(int_roundings, negative_impls))]
#![cfg_attr(all(feature = "nightly", feature = "alloc"), feature(new_uninit))]
#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(feature = "alloc_api", feature(allocator_api))]
#![cfg_attr(feature = "const", feature(const_trait_impl))]
#![cfg_attr(docsrs, feature(doc_cfg))]
#[cfg(feature = "alloc")]
pub(crate) extern crate alloc;
macro_rules! flat_mod {
($($i:ident),+) => {
$(
mod $i;
pub use $i::*;
)+
};
}
cfg_if::cfg_if! {
if #[cfg(feature = "alloc_api")] {
pub use core::alloc::AllocError;
} else {
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub struct AllocError;
#[cfg(feature = "std")]
impl std::error::Error for AllocError {}
impl core::fmt::Display for AllocError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.write_str("memory allocation failed")
}
}
}
}
cfg_if::cfg_if! {
if #[cfg(feature = "alloc")] {
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
pub mod fill_queue;
#[cfg(feature = "nightly")]
#[cfg_attr(docsrs, doc(cfg(all(feature = "alloc", feature = "nightly"))))]
pub mod bitfield;
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
pub mod flag;
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
pub mod channel;
pub(crate) mod locks;
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
pub use fill_queue::FillQueue;
#[docfg::docfg(all(feature = "alloc", feature = "nightly"))]
pub use bitfield::AtomicBitBox;
}
}
flat_mod!(take);
#[path = "trait.rs"]
pub mod traits;
pub mod prelude {
#[docfg::docfg(feature = "alloc")]
pub use crate::fill_queue::*;
pub use crate::take::*;
pub use crate::traits::Atomic;
}
cfg_if::cfg_if! {
if #[cfg(target_has_atomic = "8")] {
pub(crate) type InnerFlag = u8;
pub(crate) type InnerAtomicFlag = core::sync::atomic::AtomicU8;
} else if #[cfg(target_has_atomic = "16")] {
pub(crate) type InnerFlag = u16;
pub(crate) type InnerAtomicFlag = core::sync::atomic::AtomicU16;
} else if #[cfg(target_has_atomic = "32")] {
pub(crate) type InnerFlag = u32;
pub(crate) type InnerAtomicFlag = core::sync::atomic::AtomicU32;
} else if #[cfg(target_has_atomic = "64")] {
pub(crate) type InnerFlag = u64;
pub(crate) type InnerAtomicFlag = core::sync::atomic::AtomicU64;
} else {
pub(crate) type InnerFlag = usize;
pub(crate) type InnerAtomicFlag = core::sync::atomic::AtomicUsize;
}
}
pub(crate) const TRUE : InnerFlag = 1;
pub(crate) const FALSE : InnerFlag = 0;
#[allow(unused)]
#[inline]
pub(crate) fn is_some_and<T, F: FnOnce(T) -> bool> (v: Option<T>, f: F) -> bool {
match v {
None => false,
Some(x) => f(x),
}
}