Coverage Report

Created: 2026-07-16 07:06

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/sharded-slab-0.1.7/src/sync.rs
Line
Count
Source
1
pub(crate) use self::inner::*;
2
3
#[cfg(all(loom, any(test, feature = "loom")))]
4
mod inner {
5
    pub(crate) mod atomic {
6
        pub use loom::sync::atomic::*;
7
        pub use std::sync::atomic::Ordering;
8
    }
9
    pub(crate) use loom::{
10
        cell::UnsafeCell, hint, lazy_static, sync::Mutex, thread::yield_now, thread_local,
11
    };
12
13
    pub(crate) mod alloc {
14
        #![allow(dead_code)]
15
        use loom::alloc;
16
        use std::fmt;
17
        /// Track allocations, detecting leaks
18
        ///
19
        /// This is a version of `loom::alloc::Track` that adds a missing
20
        /// `Default` impl.
21
        pub struct Track<T>(alloc::Track<T>);
22
23
        impl<T> Track<T> {
24
            /// Track a value for leaks
25
            #[inline(always)]
26
            pub fn new(value: T) -> Track<T> {
27
                Track(alloc::Track::new(value))
28
            }
29
30
            /// Get a reference to the value
31
            #[inline(always)]
32
            pub fn get_ref(&self) -> &T {
33
                self.0.get_ref()
34
            }
35
36
            /// Get a mutable reference to the value
37
            #[inline(always)]
38
            pub fn get_mut(&mut self) -> &mut T {
39
                self.0.get_mut()
40
            }
41
42
            /// Stop tracking the value for leaks
43
            #[inline(always)]
44
            pub fn into_inner(self) -> T {
45
                self.0.into_inner()
46
            }
47
        }
48
49
        impl<T: fmt::Debug> fmt::Debug for Track<T> {
50
            fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
51
                self.0.fmt(f)
52
            }
53
        }
54
55
        impl<T: Default> Default for Track<T> {
56
            fn default() -> Self {
57
                Self::new(T::default())
58
            }
59
        }
60
    }
61
}
62
63
#[cfg(not(all(loom, any(feature = "loom", test))))]
64
mod inner {
65
    #![allow(dead_code)]
66
    pub(crate) use lazy_static::lazy_static;
67
    pub(crate) use std::{
68
        sync::{atomic, Mutex},
69
        thread::yield_now,
70
        thread_local,
71
    };
72
73
    pub(crate) mod hint {
74
        #[inline(always)]
75
0
        pub(crate) fn spin_loop() {
76
            // MSRV: std::hint::spin_loop() stabilized in 1.49.0
77
            #[allow(deprecated)]
78
0
            super::atomic::spin_loop_hint()
79
0
        }
80
    }
81
82
    #[derive(Debug)]
83
    pub(crate) struct UnsafeCell<T>(std::cell::UnsafeCell<T>);
84
85
    impl<T> UnsafeCell<T> {
86
0
        pub fn new(data: T) -> UnsafeCell<T> {
87
0
            UnsafeCell(std::cell::UnsafeCell::new(data))
88
0
        }
Unexecuted instantiation: <sharded_slab::sync::inner::UnsafeCell<core::option::Option<alloc::boxed::Box<[sharded_slab::page::slot::Slot<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>]>>>>::new
Unexecuted instantiation: <sharded_slab::sync::inner::UnsafeCell<tracing_subscriber::registry::sharded::DataInner>>::new
Unexecuted instantiation: <sharded_slab::sync::inner::UnsafeCell<usize>>::new
89
90
        #[inline(always)]
91
0
        pub fn with<F, R>(&self, f: F) -> R
92
0
        where
93
0
            F: FnOnce(*const T) -> R,
94
        {
95
0
            f(self.0.get())
96
0
        }
Unexecuted instantiation: <sharded_slab::sync::inner::UnsafeCell<core::option::Option<alloc::boxed::Box<[sharded_slab::page::slot::Slot<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>]>>>>::with::<<sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::with_slot<sharded_slab::page::slot::Guard<tracing_subscriber::registry::sharded::DataInner>, <sharded_slab::pool::Pool<tracing_subscriber::registry::sharded::DataInner>>::get::{closure#0}>::{closure#0}, core::option::Option<sharded_slab::page::slot::Guard<tracing_subscriber::registry::sharded::DataInner>>>
Unexecuted instantiation: <sharded_slab::sync::inner::UnsafeCell<core::option::Option<alloc::boxed::Box<[sharded_slab::page::slot::Slot<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>]>>>>::with::<<sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::mark_clear<sharded_slab::page::Local>::{closure#0}, bool>
Unexecuted instantiation: <sharded_slab::sync::inner::UnsafeCell<core::option::Option<alloc::boxed::Box<[sharded_slab::page::slot::Slot<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>]>>>>::with::<<sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::mark_clear<sharded_slab::page::stack::TransferStack>::{closure#0}, bool>
Unexecuted instantiation: <sharded_slab::sync::inner::UnsafeCell<core::option::Option<alloc::boxed::Box<[sharded_slab::page::slot::Slot<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>]>>>>::with::<<sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::clear<sharded_slab::page::Local>::{closure#0}, bool>
Unexecuted instantiation: <sharded_slab::sync::inner::UnsafeCell<core::option::Option<alloc::boxed::Box<[sharded_slab::page::slot::Slot<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>]>>>>::with::<<sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::clear<sharded_slab::page::stack::TransferStack>::{closure#0}, bool>
Unexecuted instantiation: <sharded_slab::sync::inner::UnsafeCell<core::option::Option<alloc::boxed::Box<[sharded_slab::page::slot::Slot<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>]>>>>::with::<<sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::init_with<(usize, sharded_slab::page::slot::InitGuard<tracing_subscriber::registry::sharded::DataInner>), &mut <sharded_slab::pool::Pool<tracing_subscriber::registry::sharded::DataInner>>::create::{closure#0}>::{closure#0}, core::option::Option<(usize, sharded_slab::page::slot::InitGuard<tracing_subscriber::registry::sharded::DataInner>)>>
Unexecuted instantiation: <sharded_slab::sync::inner::UnsafeCell<core::option::Option<alloc::boxed::Box<[sharded_slab::page::slot::Slot<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>]>>>>::with::<<sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::is_unallocated::{closure#0}, bool>
Unexecuted instantiation: <sharded_slab::sync::inner::UnsafeCell<usize>>::with::<<sharded_slab::page::Local>::head::{closure#0}, usize>
Unexecuted instantiation: <sharded_slab::sync::inner::UnsafeCell<usize>>::with::<<sharded_slab::page::slot::Slot<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::next::{closure#0}, usize>
Unexecuted instantiation: <sharded_slab::sync::inner::UnsafeCell<tracing_subscriber::registry::sharded::DataInner>>::with::<<sharded_slab::page::slot::Guard<tracing_subscriber::registry::sharded::DataInner>>::value::{closure#0}, &tracing_subscriber::registry::sharded::DataInner>
Unexecuted instantiation: <sharded_slab::sync::inner::UnsafeCell<usize>>::with::<<sharded_slab::page::Local as core::fmt::Debug>::fmt::{closure#0}, core::result::Result<(), core::fmt::Error>>
97
98
        #[inline(always)]
99
0
        pub fn with_mut<F, R>(&self, f: F) -> R
100
0
        where
101
0
            F: FnOnce(*mut T) -> R,
102
        {
103
0
            f(self.0.get())
104
0
        }
Unexecuted instantiation: <sharded_slab::sync::inner::UnsafeCell<core::option::Option<alloc::boxed::Box<[sharded_slab::page::slot::Slot<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>]>>>>::with_mut::<<sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::allocate::{closure#0}, ()>
Unexecuted instantiation: <sharded_slab::sync::inner::UnsafeCell<usize>>::with_mut::<<sharded_slab::page::Local>::set_head::{closure#0}, ()>
Unexecuted instantiation: <sharded_slab::sync::inner::UnsafeCell<usize>>::with_mut::<<sharded_slab::page::slot::Slot<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::set_next::{closure#0}, ()>
Unexecuted instantiation: <sharded_slab::sync::inner::UnsafeCell<tracing_subscriber::registry::sharded::DataInner>>::with_mut::<<sharded_slab::page::slot::Slot<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::release_with<sharded_slab::page::Local, <sharded_slab::page::slot::Slot<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::clear_storage<sharded_slab::page::Local>::{closure#0}, bool>::{closure#0}, bool>
Unexecuted instantiation: <sharded_slab::sync::inner::UnsafeCell<tracing_subscriber::registry::sharded::DataInner>>::with_mut::<<sharded_slab::page::slot::Slot<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::release_with<sharded_slab::page::stack::TransferStack, <sharded_slab::page::slot::Slot<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::clear_storage<sharded_slab::page::stack::TransferStack>::{closure#0}, bool>::{closure#0}, bool>
Unexecuted instantiation: <sharded_slab::sync::inner::UnsafeCell<tracing_subscriber::registry::sharded::DataInner>>::with_mut::<<sharded_slab::page::slot::InitGuard<tracing_subscriber::registry::sharded::DataInner>>::value_mut::{closure#0}, &mut tracing_subscriber::registry::sharded::DataInner>
Unexecuted instantiation: <sharded_slab::sync::inner::UnsafeCell<_>>::with_mut::<_, _>
105
    }
106
107
    pub(crate) mod alloc {
108
        /// Track allocations, detecting leaks
109
        #[derive(Debug, Default)]
110
        pub struct Track<T> {
111
            value: T,
112
        }
113
114
        impl<T> Track<T> {
115
            /// Track a value for leaks
116
            #[inline(always)]
117
0
            pub fn new(value: T) -> Track<T> {
118
0
                Track { value }
119
0
            }
Unexecuted instantiation: <sharded_slab::sync::inner::alloc::Track<sharded_slab::shard::Shard<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>>::new
Unexecuted instantiation: <sharded_slab::sync::inner::alloc::Track<_>>::new
120
121
            /// Get a reference to the value
122
            #[inline(always)]
123
0
            pub fn get_ref(&self) -> &T {
124
0
                &self.value
125
0
            }
Unexecuted instantiation: <sharded_slab::sync::inner::alloc::Track<sharded_slab::shard::Shard<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>>::get_ref
Unexecuted instantiation: <sharded_slab::sync::inner::alloc::Track<_>>::get_ref
126
127
            /// Get a mutable reference to the value
128
            #[inline(always)]
129
0
            pub fn get_mut(&mut self) -> &mut T {
130
0
                &mut self.value
131
0
            }
132
133
            /// Stop tracking the value for leaks
134
            #[inline(always)]
135
0
            pub fn into_inner(self) -> T {
136
0
                self.value
137
0
            }
138
        }
139
    }
140
}