/rust/registry/src/index.crates.io-6f17d22bba15001f/sharded-slab-0.1.7/src/page/mod.rs
Line | Count | Source (jump to first uncovered line) |
1 | | use crate::cfg::{self, CfgPrivate}; |
2 | | use crate::clear::Clear; |
3 | | use crate::sync::UnsafeCell; |
4 | | use crate::Pack; |
5 | | |
6 | | pub(crate) mod slot; |
7 | | mod stack; |
8 | | pub(crate) use self::slot::Slot; |
9 | | use std::{fmt, marker::PhantomData}; |
10 | | |
11 | | /// A page address encodes the location of a slot within a shard (the page |
12 | | /// number and offset within that page) as a single linear value. |
13 | | #[repr(transparent)] |
14 | | pub(crate) struct Addr<C: cfg::Config = cfg::DefaultConfig> { |
15 | | addr: usize, |
16 | | _cfg: PhantomData<fn(C)>, |
17 | | } |
18 | | |
19 | | impl<C: cfg::Config> Addr<C> { |
20 | | const NULL: usize = Self::BITS + 1; |
21 | | |
22 | 0 | pub(crate) fn index(self) -> usize { |
23 | 0 | // Since every page is twice as large as the previous page, and all page sizes |
24 | 0 | // are powers of two, we can determine the page index that contains a given |
25 | 0 | // address by counting leading zeros, which tells us what power of two |
26 | 0 | // the offset fits into. |
27 | 0 | // |
28 | 0 | // First, we must shift down to the smallest page size, so that the last |
29 | 0 | // offset on the first page becomes 0. |
30 | 0 | let shifted = (self.addr + C::INITIAL_SZ) >> C::ADDR_INDEX_SHIFT; |
31 | 0 | // Now, we can determine the number of twos places by counting the |
32 | 0 | // number of leading zeros (unused twos places) in the number's binary |
33 | 0 | // representation, and subtracting that count from the total number of bits in a word. |
34 | 0 | cfg::WIDTH - shifted.leading_zeros() as usize |
35 | 0 | } Unexecuted instantiation: <sharded_slab::page::Addr>::index Unexecuted instantiation: <sharded_slab::page::Addr<_>>::index Unexecuted instantiation: <sharded_slab::page::Addr>::index Unexecuted instantiation: <sharded_slab::page::Addr>::index Unexecuted instantiation: <sharded_slab::page::Addr>::index Unexecuted instantiation: <sharded_slab::page::Addr>::index Unexecuted instantiation: <sharded_slab::page::Addr>::index |
36 | | |
37 | 0 | pub(crate) fn offset(self) -> usize { |
38 | 0 | self.addr |
39 | 0 | } Unexecuted instantiation: <sharded_slab::page::Addr>::offset Unexecuted instantiation: <sharded_slab::page::Addr<_>>::offset Unexecuted instantiation: <sharded_slab::page::Addr>::offset Unexecuted instantiation: <sharded_slab::page::Addr>::offset Unexecuted instantiation: <sharded_slab::page::Addr>::offset Unexecuted instantiation: <sharded_slab::page::Addr>::offset Unexecuted instantiation: <sharded_slab::page::Addr>::offset |
40 | | } |
41 | | |
42 | | pub(crate) trait FreeList<C> { |
43 | | fn push<T>(&self, new_head: usize, slot: &Slot<T, C>) |
44 | | where |
45 | | C: cfg::Config; |
46 | | } |
47 | | |
48 | | impl<C: cfg::Config> Pack<C> for Addr<C> { |
49 | | const LEN: usize = C::MAX_PAGES + C::ADDR_INDEX_SHIFT; |
50 | | |
51 | | type Prev = (); |
52 | | |
53 | 0 | fn as_usize(&self) -> usize { |
54 | 0 | self.addr |
55 | 0 | } |
56 | | |
57 | 0 | fn from_usize(addr: usize) -> Self { |
58 | 0 | debug_assert!(addr <= Self::BITS); |
59 | 0 | Self { |
60 | 0 | addr, |
61 | 0 | _cfg: PhantomData, |
62 | 0 | } |
63 | 0 | } Unexecuted instantiation: <sharded_slab::page::Addr as sharded_slab::Pack<sharded_slab::cfg::DefaultConfig>>::from_usize Unexecuted instantiation: <sharded_slab::page::Addr<_> as sharded_slab::Pack<_>>::from_usize Unexecuted instantiation: <sharded_slab::page::Addr as sharded_slab::Pack<sharded_slab::cfg::DefaultConfig>>::from_usize Unexecuted instantiation: <sharded_slab::page::Addr as sharded_slab::Pack<sharded_slab::cfg::DefaultConfig>>::from_usize Unexecuted instantiation: <sharded_slab::page::Addr as sharded_slab::Pack<sharded_slab::cfg::DefaultConfig>>::from_usize Unexecuted instantiation: <sharded_slab::page::Addr as sharded_slab::Pack<sharded_slab::cfg::DefaultConfig>>::from_usize Unexecuted instantiation: <sharded_slab::page::Addr as sharded_slab::Pack<sharded_slab::cfg::DefaultConfig>>::from_usize |
64 | | } |
65 | | |
66 | | pub(crate) type Iter<'a, T, C> = std::iter::FilterMap< |
67 | | std::slice::Iter<'a, Slot<Option<T>, C>>, |
68 | | fn(&'a Slot<Option<T>, C>) -> Option<&'a T>, |
69 | | >; |
70 | | |
71 | | pub(crate) struct Local { |
72 | | /// Index of the first slot on the local free list |
73 | | head: UnsafeCell<usize>, |
74 | | } |
75 | | |
76 | | pub(crate) struct Shared<T, C> { |
77 | | /// The remote free list |
78 | | /// |
79 | | /// Slots freed from a remote thread are pushed onto this list. |
80 | | remote: stack::TransferStack<C>, |
81 | | // Total size of the page. |
82 | | // |
83 | | // If the head index of the local or remote free list is greater than the size of the |
84 | | // page, then that free list is emtpy. If the head of both free lists is greater than `size` |
85 | | // then there are no slots left in that page. |
86 | | size: usize, |
87 | | prev_sz: usize, |
88 | | slab: UnsafeCell<Option<Slots<T, C>>>, |
89 | | } |
90 | | |
91 | | type Slots<T, C> = Box<[Slot<T, C>]>; |
92 | | |
93 | | impl Local { |
94 | 0 | pub(crate) fn new() -> Self { |
95 | 0 | Self { |
96 | 0 | head: UnsafeCell::new(0), |
97 | 0 | } |
98 | 0 | } |
99 | | |
100 | | #[inline(always)] |
101 | 0 | fn head(&self) -> usize { |
102 | 0 | self.head.with(|head| unsafe { *head }) Unexecuted instantiation: <sharded_slab::page::Local>::head::{closure#0} Unexecuted instantiation: <sharded_slab::page::Local>::head::{closure#0} Unexecuted instantiation: <sharded_slab::page::Local>::head::{closure#0} Unexecuted instantiation: <sharded_slab::page::Local>::head::{closure#0} Unexecuted instantiation: <sharded_slab::page::Local>::head::{closure#0} Unexecuted instantiation: <sharded_slab::page::Local>::head::{closure#0} Unexecuted instantiation: <sharded_slab::page::Local>::head::{closure#0} |
103 | 0 | } |
104 | | |
105 | | #[inline(always)] |
106 | 0 | fn set_head(&self, new_head: usize) { |
107 | 0 | self.head.with_mut(|head| unsafe { |
108 | 0 | *head = new_head; |
109 | 0 | }) Unexecuted instantiation: <sharded_slab::page::Local>::set_head::{closure#0} Unexecuted instantiation: <sharded_slab::page::Local>::set_head::{closure#0} Unexecuted instantiation: <sharded_slab::page::Local>::set_head::{closure#0} Unexecuted instantiation: <sharded_slab::page::Local>::set_head::{closure#0} Unexecuted instantiation: <sharded_slab::page::Local>::set_head::{closure#0} Unexecuted instantiation: <sharded_slab::page::Local>::set_head::{closure#0} Unexecuted instantiation: <sharded_slab::page::Local>::set_head::{closure#0} |
110 | 0 | } |
111 | | } |
112 | | |
113 | | impl<C: cfg::Config> FreeList<C> for Local { |
114 | 0 | fn push<T>(&self, new_head: usize, slot: &Slot<T, C>) { |
115 | 0 | slot.set_next(self.head()); |
116 | 0 | self.set_head(new_head); |
117 | 0 | } Unexecuted instantiation: <sharded_slab::page::Local as sharded_slab::page::FreeList<sharded_slab::cfg::DefaultConfig>>::push::<tracing_subscriber::registry::sharded::DataInner> Unexecuted instantiation: <sharded_slab::page::Local as sharded_slab::page::FreeList<_>>::push::<_> Unexecuted instantiation: <sharded_slab::page::Local as sharded_slab::page::FreeList<sharded_slab::cfg::DefaultConfig>>::push::<tracing_subscriber::registry::sharded::DataInner> Unexecuted instantiation: <sharded_slab::page::Local as sharded_slab::page::FreeList<sharded_slab::cfg::DefaultConfig>>::push::<tracing_subscriber::registry::sharded::DataInner> Unexecuted instantiation: <sharded_slab::page::Local as sharded_slab::page::FreeList<sharded_slab::cfg::DefaultConfig>>::push::<tracing_subscriber::registry::sharded::DataInner> Unexecuted instantiation: <sharded_slab::page::Local as sharded_slab::page::FreeList<sharded_slab::cfg::DefaultConfig>>::push::<tracing_subscriber::registry::sharded::DataInner> Unexecuted instantiation: <sharded_slab::page::Local as sharded_slab::page::FreeList<sharded_slab::cfg::DefaultConfig>>::push::<tracing_subscriber::registry::sharded::DataInner> |
118 | | } |
119 | | |
120 | | impl<T, C> Shared<T, C> |
121 | | where |
122 | | C: cfg::Config, |
123 | | { |
124 | | const NULL: usize = Addr::<C>::NULL; |
125 | | |
126 | 0 | pub(crate) fn new(size: usize, prev_sz: usize) -> Self { |
127 | 0 | Self { |
128 | 0 | prev_sz, |
129 | 0 | size, |
130 | 0 | remote: stack::TransferStack::new(), |
131 | 0 | slab: UnsafeCell::new(None), |
132 | 0 | } |
133 | 0 | } Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::new Unexecuted instantiation: <sharded_slab::page::Shared<_, _>>::new Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::new Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::new Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::new Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::new Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::new |
134 | | |
135 | | /// Return the head of the freelist |
136 | | /// |
137 | | /// If there is space on the local list, it returns the head of the local list. Otherwise, it |
138 | | /// pops all the slots from the global list and returns the head of that list |
139 | | /// |
140 | | /// *Note*: The local list's head is reset when setting the new state in the slot pointed to be |
141 | | /// `head` returned from this function |
142 | | #[inline] |
143 | 0 | fn pop(&self, local: &Local) -> Option<usize> { |
144 | 0 | let head = local.head(); |
145 | 0 |
|
146 | 0 | test_println!("-> local head {:?}", head); |
147 | | |
148 | | // are there any items on the local free list? (fast path) |
149 | 0 | let head = if head < self.size { |
150 | 0 | head |
151 | | } else { |
152 | | // slow path: if the local free list is empty, pop all the items on |
153 | | // the remote free list. |
154 | 0 | let head = self.remote.pop_all(); |
155 | 0 |
|
156 | 0 | test_println!("-> remote head {:?}", head); |
157 | 0 | head? |
158 | | }; |
159 | | |
160 | | // if the head is still null, both the local and remote free lists are |
161 | | // empty --- we can't fit any more items on this page. |
162 | 0 | if head == Self::NULL { |
163 | 0 | test_println!("-> NULL! {:?}", head); |
164 | 0 | None |
165 | | } else { |
166 | 0 | Some(head) |
167 | | } |
168 | 0 | } Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::pop Unexecuted instantiation: <sharded_slab::page::Shared<_, _>>::pop Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::pop Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::pop Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::pop Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::pop Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::pop |
169 | | |
170 | | /// Returns `true` if storage is currently allocated for this page, `false` |
171 | | /// otherwise. |
172 | | #[inline] |
173 | 0 | fn is_unallocated(&self) -> bool { |
174 | 0 | self.slab.with(|s| unsafe { (*s).is_none() }) Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::is_unallocated::{closure#0} Unexecuted instantiation: <sharded_slab::page::Shared<_, _>>::is_unallocated::{closure#0} Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::is_unallocated::{closure#0} Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::is_unallocated::{closure#0} Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::is_unallocated::{closure#0} Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::is_unallocated::{closure#0} Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::is_unallocated::{closure#0} |
175 | 0 | } Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::is_unallocated Unexecuted instantiation: <sharded_slab::page::Shared<_, _>>::is_unallocated Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::is_unallocated Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::is_unallocated Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::is_unallocated Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::is_unallocated Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::is_unallocated |
176 | | |
177 | | #[inline] |
178 | 0 | pub(crate) fn with_slot<'a, U>( |
179 | 0 | &'a self, |
180 | 0 | addr: Addr<C>, |
181 | 0 | f: impl FnOnce(&'a Slot<T, C>) -> Option<U>, |
182 | 0 | ) -> Option<U> { |
183 | 0 | let poff = addr.offset() - self.prev_sz; |
184 | 0 |
|
185 | 0 | test_println!("-> offset {:?}", poff); |
186 | | |
187 | 0 | self.slab.with(|slab| { |
188 | 0 | let slot = unsafe { &*slab }.as_ref()?.get(poff)?; |
189 | 0 | f(slot) |
190 | 0 | }) Unexecuted instantiation: <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} Unexecuted instantiation: <sharded_slab::page::Shared<_, _>>::with_slot::<_, _>::{closure#0} Unexecuted instantiation: <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} Unexecuted instantiation: <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} Unexecuted instantiation: <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} Unexecuted instantiation: <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} Unexecuted instantiation: <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} |
191 | 0 | } Unexecuted instantiation: <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}> Unexecuted instantiation: <sharded_slab::page::Shared<_, _>>::with_slot::<_, _> Unexecuted instantiation: <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}> Unexecuted instantiation: <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}> Unexecuted instantiation: <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}> Unexecuted instantiation: <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}> Unexecuted instantiation: <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}> |
192 | | |
193 | | #[inline(always)] |
194 | 0 | pub(crate) fn free_list(&self) -> &impl FreeList<C> { |
195 | 0 | &self.remote |
196 | 0 | } Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::free_list Unexecuted instantiation: <sharded_slab::page::Shared<_, _>>::free_list Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::free_list Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::free_list Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::free_list Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::free_list Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::free_list |
197 | | } |
198 | | |
199 | | impl<'a, T, C> Shared<Option<T>, C> |
200 | | where |
201 | | C: cfg::Config + 'a, |
202 | | { |
203 | 0 | pub(crate) fn take<F>( |
204 | 0 | &self, |
205 | 0 | addr: Addr<C>, |
206 | 0 | gen: slot::Generation<C>, |
207 | 0 | free_list: &F, |
208 | 0 | ) -> Option<T> |
209 | 0 | where |
210 | 0 | F: FreeList<C>, |
211 | 0 | { |
212 | 0 | let offset = addr.offset() - self.prev_sz; |
213 | 0 |
|
214 | 0 | test_println!("-> take: offset {:?}", offset); |
215 | | |
216 | 0 | self.slab.with(|slab| { |
217 | 0 | let slab = unsafe { &*slab }.as_ref()?; |
218 | 0 | let slot = slab.get(offset)?; |
219 | 0 | slot.remove_value(gen, offset, free_list) |
220 | 0 | }) |
221 | 0 | } |
222 | | |
223 | 0 | pub(crate) fn remove<F: FreeList<C>>( |
224 | 0 | &self, |
225 | 0 | addr: Addr<C>, |
226 | 0 | gen: slot::Generation<C>, |
227 | 0 | free_list: &F, |
228 | 0 | ) -> bool { |
229 | 0 | let offset = addr.offset() - self.prev_sz; |
230 | 0 |
|
231 | 0 | test_println!("-> offset {:?}", offset); |
232 | | |
233 | 0 | self.slab.with(|slab| { |
234 | 0 | let slab = unsafe { &*slab }.as_ref(); |
235 | 0 | if let Some(slot) = slab.and_then(|slab| slab.get(offset)) { |
236 | 0 | slot.try_remove_value(gen, offset, free_list) |
237 | | } else { |
238 | 0 | false |
239 | | } |
240 | 0 | }) |
241 | 0 | } |
242 | | |
243 | | // Need this function separately, as we need to pass a function pointer to `filter_map` and |
244 | | // `Slot::value` just returns a `&T`, specifically a `&Option<T>` for this impl. |
245 | 0 | fn make_ref(slot: &'a Slot<Option<T>, C>) -> Option<&'a T> { |
246 | 0 | slot.value().as_ref() |
247 | 0 | } |
248 | | |
249 | 0 | pub(crate) fn iter(&self) -> Option<Iter<'a, T, C>> { |
250 | 0 | let slab = self.slab.with(|slab| unsafe { (*slab).as_ref() }); |
251 | 0 | slab.map(|slab| { |
252 | 0 | slab.iter() |
253 | 0 | .filter_map(Shared::make_ref as fn(&'a Slot<Option<T>, C>) -> Option<&'a T>) |
254 | 0 | }) |
255 | 0 | } |
256 | | } |
257 | | |
258 | | impl<T, C> Shared<T, C> |
259 | | where |
260 | | T: Clear + Default, |
261 | | C: cfg::Config, |
262 | | { |
263 | 0 | pub(crate) fn init_with<U>( |
264 | 0 | &self, |
265 | 0 | local: &Local, |
266 | 0 | init: impl FnOnce(usize, &Slot<T, C>) -> Option<U>, |
267 | 0 | ) -> Option<U> { |
268 | 0 | let head = self.pop(local)?; |
269 | | |
270 | | // do we need to allocate storage for this page? |
271 | 0 | if self.is_unallocated() { |
272 | 0 | self.allocate(); |
273 | 0 | } |
274 | | |
275 | 0 | let index = head + self.prev_sz; |
276 | | |
277 | 0 | let result = self.slab.with(|slab| { |
278 | 0 | let slab = unsafe { &*(slab) } |
279 | 0 | .as_ref() |
280 | 0 | .expect("page must have been allocated to insert!"); |
281 | 0 | let slot = &slab[head]; |
282 | 0 | let result = init(index, slot)?; |
283 | 0 | local.set_head(slot.next()); |
284 | 0 | Some(result) |
285 | 0 | })?; Unexecuted instantiation: <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} Unexecuted instantiation: <sharded_slab::page::Shared<_, _>>::init_with::<_, _>::{closure#0} Unexecuted instantiation: <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} Unexecuted instantiation: <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} Unexecuted instantiation: <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} Unexecuted instantiation: <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} Unexecuted instantiation: <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} |
286 | | |
287 | 0 | test_println!("-> init_with: insert at offset: {}", index); |
288 | 0 | Some(result) |
289 | 0 | } Unexecuted instantiation: <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}> Unexecuted instantiation: <sharded_slab::page::Shared<_, _>>::init_with::<_, _> Unexecuted instantiation: <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}> Unexecuted instantiation: <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}> Unexecuted instantiation: <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}> Unexecuted instantiation: <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}> Unexecuted instantiation: <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}> |
290 | | |
291 | | /// Allocates storage for the page's slots. |
292 | | #[cold] |
293 | 0 | fn allocate(&self) { |
294 | 0 | test_println!("-> alloc new page ({})", self.size); |
295 | 0 | debug_assert!(self.is_unallocated()); |
296 | | |
297 | 0 | let mut slab = Vec::with_capacity(self.size); |
298 | 0 | slab.extend((1..self.size).map(Slot::new)); |
299 | 0 | slab.push(Slot::new(Self::NULL)); |
300 | 0 | self.slab.with_mut(|s| { |
301 | 0 | // safety: this mut access is safe — it only occurs to initially allocate the page, |
302 | 0 | // which only happens on this thread; if the page has not yet been allocated, other |
303 | 0 | // threads will not try to access it yet. |
304 | 0 | unsafe { |
305 | 0 | *s = Some(slab.into_boxed_slice()); |
306 | 0 | } |
307 | 0 | }); Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::allocate::{closure#0} Unexecuted instantiation: <sharded_slab::page::Shared<_, _>>::allocate::{closure#0} Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::allocate::{closure#0} Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::allocate::{closure#0} Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::allocate::{closure#0} Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::allocate::{closure#0} Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::allocate::{closure#0} |
308 | 0 | } Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::allocate Unexecuted instantiation: <sharded_slab::page::Shared<_, _>>::allocate Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::allocate Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::allocate Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::allocate Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::allocate Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::allocate |
309 | | |
310 | 0 | pub(crate) fn mark_clear<F: FreeList<C>>( |
311 | 0 | &self, |
312 | 0 | addr: Addr<C>, |
313 | 0 | gen: slot::Generation<C>, |
314 | 0 | free_list: &F, |
315 | 0 | ) -> bool { |
316 | 0 | let offset = addr.offset() - self.prev_sz; |
317 | 0 |
|
318 | 0 | test_println!("-> offset {:?}", offset); |
319 | | |
320 | 0 | self.slab.with(|slab| { |
321 | 0 | let slab = unsafe { &*slab }.as_ref(); |
322 | 0 | if let Some(slot) = slab.and_then(|slab| slab.get(offset)) { Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::mark_clear::<sharded_slab::page::Local>::{closure#0}::{closure#0} Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::mark_clear::<sharded_slab::page::stack::TransferStack>::{closure#0}::{closure#0} Unexecuted instantiation: <sharded_slab::page::Shared<_, _>>::mark_clear::<_>::{closure#0}::{closure#0} Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::mark_clear::<sharded_slab::page::Local>::{closure#0}::{closure#0} Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::mark_clear::<sharded_slab::page::stack::TransferStack>::{closure#0}::{closure#0} Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::mark_clear::<sharded_slab::page::Local>::{closure#0}::{closure#0} Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::mark_clear::<sharded_slab::page::stack::TransferStack>::{closure#0}::{closure#0} Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::mark_clear::<sharded_slab::page::Local>::{closure#0}::{closure#0} Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::mark_clear::<sharded_slab::page::stack::TransferStack>::{closure#0}::{closure#0} Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::mark_clear::<sharded_slab::page::Local>::{closure#0}::{closure#0} Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::mark_clear::<sharded_slab::page::stack::TransferStack>::{closure#0}::{closure#0} Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::mark_clear::<sharded_slab::page::Local>::{closure#0}::{closure#0} Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::mark_clear::<sharded_slab::page::stack::TransferStack>::{closure#0}::{closure#0} |
323 | 0 | slot.try_clear_storage(gen, offset, free_list) |
324 | | } else { |
325 | 0 | false |
326 | | } |
327 | 0 | }) Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::mark_clear::<sharded_slab::page::Local>::{closure#0} Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::mark_clear::<sharded_slab::page::stack::TransferStack>::{closure#0} Unexecuted instantiation: <sharded_slab::page::Shared<_, _>>::mark_clear::<_>::{closure#0} Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::mark_clear::<sharded_slab::page::Local>::{closure#0} Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::mark_clear::<sharded_slab::page::stack::TransferStack>::{closure#0} Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::mark_clear::<sharded_slab::page::Local>::{closure#0} Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::mark_clear::<sharded_slab::page::stack::TransferStack>::{closure#0} Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::mark_clear::<sharded_slab::page::Local>::{closure#0} Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::mark_clear::<sharded_slab::page::stack::TransferStack>::{closure#0} Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::mark_clear::<sharded_slab::page::Local>::{closure#0} Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::mark_clear::<sharded_slab::page::stack::TransferStack>::{closure#0} Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::mark_clear::<sharded_slab::page::Local>::{closure#0} Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::mark_clear::<sharded_slab::page::stack::TransferStack>::{closure#0} |
328 | 0 | } Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::mark_clear::<sharded_slab::page::Local> Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::mark_clear::<sharded_slab::page::stack::TransferStack> Unexecuted instantiation: <sharded_slab::page::Shared<_, _>>::mark_clear::<_> Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::mark_clear::<sharded_slab::page::Local> Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::mark_clear::<sharded_slab::page::stack::TransferStack> Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::mark_clear::<sharded_slab::page::Local> Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::mark_clear::<sharded_slab::page::stack::TransferStack> Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::mark_clear::<sharded_slab::page::Local> Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::mark_clear::<sharded_slab::page::stack::TransferStack> Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::mark_clear::<sharded_slab::page::Local> Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::mark_clear::<sharded_slab::page::stack::TransferStack> Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::mark_clear::<sharded_slab::page::Local> Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::mark_clear::<sharded_slab::page::stack::TransferStack> |
329 | | |
330 | 0 | pub(crate) fn clear<F: FreeList<C>>( |
331 | 0 | &self, |
332 | 0 | addr: Addr<C>, |
333 | 0 | gen: slot::Generation<C>, |
334 | 0 | free_list: &F, |
335 | 0 | ) -> bool { |
336 | 0 | let offset = addr.offset() - self.prev_sz; |
337 | 0 |
|
338 | 0 | test_println!("-> offset {:?}", offset); |
339 | | |
340 | 0 | self.slab.with(|slab| { |
341 | 0 | let slab = unsafe { &*slab }.as_ref(); |
342 | 0 | if let Some(slot) = slab.and_then(|slab| slab.get(offset)) { Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::clear::<sharded_slab::page::Local>::{closure#0}::{closure#0} Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::clear::<sharded_slab::page::stack::TransferStack>::{closure#0}::{closure#0} Unexecuted instantiation: <sharded_slab::page::Shared<_, _>>::clear::<_>::{closure#0}::{closure#0} Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::clear::<sharded_slab::page::Local>::{closure#0}::{closure#0} Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::clear::<sharded_slab::page::stack::TransferStack>::{closure#0}::{closure#0} Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::clear::<sharded_slab::page::Local>::{closure#0}::{closure#0} Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::clear::<sharded_slab::page::stack::TransferStack>::{closure#0}::{closure#0} Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::clear::<sharded_slab::page::Local>::{closure#0}::{closure#0} Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::clear::<sharded_slab::page::stack::TransferStack>::{closure#0}::{closure#0} Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::clear::<sharded_slab::page::Local>::{closure#0}::{closure#0} Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::clear::<sharded_slab::page::stack::TransferStack>::{closure#0}::{closure#0} Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::clear::<sharded_slab::page::Local>::{closure#0}::{closure#0} Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::clear::<sharded_slab::page::stack::TransferStack>::{closure#0}::{closure#0} |
343 | 0 | slot.clear_storage(gen, offset, free_list) |
344 | | } else { |
345 | 0 | false |
346 | | } |
347 | 0 | }) Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::clear::<sharded_slab::page::Local>::{closure#0} Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::clear::<sharded_slab::page::stack::TransferStack>::{closure#0} Unexecuted instantiation: <sharded_slab::page::Shared<_, _>>::clear::<_>::{closure#0} Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::clear::<sharded_slab::page::Local>::{closure#0} Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::clear::<sharded_slab::page::stack::TransferStack>::{closure#0} Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::clear::<sharded_slab::page::Local>::{closure#0} Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::clear::<sharded_slab::page::stack::TransferStack>::{closure#0} Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::clear::<sharded_slab::page::Local>::{closure#0} Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::clear::<sharded_slab::page::stack::TransferStack>::{closure#0} Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::clear::<sharded_slab::page::Local>::{closure#0} Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::clear::<sharded_slab::page::stack::TransferStack>::{closure#0} Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::clear::<sharded_slab::page::Local>::{closure#0} Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::clear::<sharded_slab::page::stack::TransferStack>::{closure#0} |
348 | 0 | } Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::clear::<sharded_slab::page::Local> Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::clear::<sharded_slab::page::stack::TransferStack> Unexecuted instantiation: <sharded_slab::page::Shared<_, _>>::clear::<_> Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::clear::<sharded_slab::page::Local> Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::clear::<sharded_slab::page::stack::TransferStack> Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::clear::<sharded_slab::page::Local> Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::clear::<sharded_slab::page::stack::TransferStack> Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::clear::<sharded_slab::page::Local> Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::clear::<sharded_slab::page::stack::TransferStack> Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::clear::<sharded_slab::page::Local> Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::clear::<sharded_slab::page::stack::TransferStack> Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::clear::<sharded_slab::page::Local> Unexecuted instantiation: <sharded_slab::page::Shared<tracing_subscriber::registry::sharded::DataInner, sharded_slab::cfg::DefaultConfig>>::clear::<sharded_slab::page::stack::TransferStack> |
349 | | } |
350 | | |
351 | | impl fmt::Debug for Local { |
352 | 0 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
353 | 0 | self.head.with(|head| { |
354 | 0 | let head = unsafe { *head }; |
355 | 0 | f.debug_struct("Local") |
356 | 0 | .field("head", &format_args!("{:#0x}", head)) |
357 | 0 | .finish() |
358 | 0 | }) |
359 | 0 | } |
360 | | } |
361 | | |
362 | | impl<C, T> fmt::Debug for Shared<C, T> { |
363 | 0 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
364 | 0 | f.debug_struct("Shared") |
365 | 0 | .field("remote", &self.remote) |
366 | 0 | .field("prev_sz", &self.prev_sz) |
367 | 0 | .field("size", &self.size) |
368 | 0 | // .field("slab", &self.slab) |
369 | 0 | .finish() |
370 | 0 | } |
371 | | } |
372 | | |
373 | | impl<C: cfg::Config> fmt::Debug for Addr<C> { |
374 | 0 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
375 | 0 | f.debug_struct("Addr") |
376 | 0 | .field("addr", &format_args!("{:#0x}", &self.addr)) |
377 | 0 | .field("index", &self.index()) |
378 | 0 | .field("offset", &self.offset()) |
379 | 0 | .finish() |
380 | 0 | } |
381 | | } |
382 | | |
383 | | impl<C: cfg::Config> PartialEq for Addr<C> { |
384 | 0 | fn eq(&self, other: &Self) -> bool { |
385 | 0 | self.addr == other.addr |
386 | 0 | } |
387 | | } |
388 | | |
389 | | impl<C: cfg::Config> Eq for Addr<C> {} |
390 | | |
391 | | impl<C: cfg::Config> PartialOrd for Addr<C> { |
392 | 0 | fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> { |
393 | 0 | self.addr.partial_cmp(&other.addr) |
394 | 0 | } |
395 | | } |
396 | | |
397 | | impl<C: cfg::Config> Ord for Addr<C> { |
398 | 0 | fn cmp(&self, other: &Self) -> std::cmp::Ordering { |
399 | 0 | self.addr.cmp(&other.addr) |
400 | 0 | } |
401 | | } |
402 | | |
403 | | impl<C: cfg::Config> Clone for Addr<C> { |
404 | 0 | fn clone(&self) -> Self { |
405 | 0 | *self |
406 | 0 | } |
407 | | } |
408 | | |
409 | | impl<C: cfg::Config> Copy for Addr<C> {} |
410 | | |
411 | | #[inline(always)] |
412 | 0 | pub(crate) fn indices<C: cfg::Config>(idx: usize) -> (Addr<C>, usize) { |
413 | 0 | let addr = C::unpack_addr(idx); |
414 | 0 | (addr, addr.index()) |
415 | 0 | } Unexecuted instantiation: sharded_slab::page::indices::<sharded_slab::cfg::DefaultConfig> Unexecuted instantiation: sharded_slab::page::indices::<_> Unexecuted instantiation: sharded_slab::page::indices::<sharded_slab::cfg::DefaultConfig> Unexecuted instantiation: sharded_slab::page::indices::<sharded_slab::cfg::DefaultConfig> Unexecuted instantiation: sharded_slab::page::indices::<sharded_slab::cfg::DefaultConfig> Unexecuted instantiation: sharded_slab::page::indices::<sharded_slab::cfg::DefaultConfig> Unexecuted instantiation: sharded_slab::page::indices::<sharded_slab::cfg::DefaultConfig> |
416 | | |
417 | | #[cfg(test)] |
418 | | mod test { |
419 | | use super::*; |
420 | | use crate::Pack; |
421 | | use proptest::prelude::*; |
422 | | |
423 | | proptest! { |
424 | | #[test] |
425 | | fn addr_roundtrips(pidx in 0usize..Addr::<cfg::DefaultConfig>::BITS) { |
426 | | let addr = Addr::<cfg::DefaultConfig>::from_usize(pidx); |
427 | | let packed = addr.pack(0); |
428 | | assert_eq!(addr, Addr::from_packed(packed)); |
429 | | } |
430 | | #[test] |
431 | | fn gen_roundtrips(gen in 0usize..slot::Generation::<cfg::DefaultConfig>::BITS) { |
432 | | let gen = slot::Generation::<cfg::DefaultConfig>::from_usize(gen); |
433 | | let packed = gen.pack(0); |
434 | | assert_eq!(gen, slot::Generation::from_packed(packed)); |
435 | | } |
436 | | |
437 | | #[test] |
438 | | fn page_roundtrips( |
439 | | gen in 0usize..slot::Generation::<cfg::DefaultConfig>::BITS, |
440 | | addr in 0usize..Addr::<cfg::DefaultConfig>::BITS, |
441 | | ) { |
442 | | let gen = slot::Generation::<cfg::DefaultConfig>::from_usize(gen); |
443 | | let addr = Addr::<cfg::DefaultConfig>::from_usize(addr); |
444 | | let packed = gen.pack(addr.pack(0)); |
445 | | assert_eq!(addr, Addr::from_packed(packed)); |
446 | | assert_eq!(gen, slot::Generation::from_packed(packed)); |
447 | | } |
448 | | } |
449 | | } |