Skip to main content

nblf_queue/core/
mod.rs

1//! Core traits and types for interface with the queues in this crate.
2//!
3//! This module contains functionality which interacts with the underlying implementations of queues.
4//! For most use cases it should not be neccessary to use any of this functionality.
5
6pub(crate) mod buffer;
7pub(crate) mod packed;
8pub(crate) mod queue;
9pub(crate) mod slot;
10
11pub use packed::{AsPackedValue, TruncatedU64};
12
13pub mod slots {
14    //! Module containing types used to determine the underlying storage type in nblf-queue Queues.
15    //! In most cases the `Auto` type, which is used as default across this crate, should suffice.
16
17    use super::*;
18    use crate::utils::Sealed;
19
20    cfg_atomic_tagged64! {
21        pub use tagged64::*;
22        mod tagged64 {
23            use super::*;
24            /// Slot type describing a tagged 64 bit value.
25            /// Only available if `target_has_atomic = "64"` is true or on feature `atomic-fallback`.
26            pub struct Tagged64;
27            impl Sealed for Tagged64 {}
28            impl<T: AsPackedValue> SlotType<T> for Tagged64 {
29                type Slot = slot::Tagged64<T>;
30            }
31        }
32    }
33
34    cfg_atomic_tagged128! {
35        pub use tagged128::*;
36        mod tagged128 {
37            use super::*;
38            /// Slot type describing a tagged 128 bit value.
39            /// Only available if `target_has_atomic = "128"` is true or on feature `atomic-fallback`.
40            pub struct Tagged128;
41            impl Sealed for Tagged128 {}
42            impl<T: AsPackedValue> SlotType<T> for Tagged128 {
43                type Slot = slot::Tagged128<T>;
44            }
45
46        }
47    }
48
49    /// Slot type which chooses a concrete implementation based on arch and feature flags.
50    pub struct Auto;
51    impl Sealed for Auto {}
52
53    #[doc(hidden)]
54    pub trait SlotType<T: AsPackedValue>: Sealed {
55        #[allow(private_bounds)]
56        type Slot: slot::Slot<Item = T>;
57    }
58
59    impl<T: AsPackedValue> SlotType<T> for Auto {
60        #[cfg(all(
61            any(target_has_atomic = "64", feature = "atomic-fallback"),
62            not(any(target_has_atomic = "128", feature = "atomic-fallback"))
63        ))]
64        type Slot = slot::Tagged64<T>;
65        #[cfg(any(target_has_atomic = "128", feature = "atomic-fallback"))]
66        type Slot = slot::Tagged128<T>;
67
68        #[cfg(all(
69            not(any(target_has_atomic = "64", feature = "atomic-fallback")),
70            not(target_has_atomic = "128")
71        ))]
72        compile_error!("target arch is currently not supported");
73    }
74}