|
4 | 4 | //! using the native OS-provided facilities (think `TlsAlloc` or
|
5 | 5 | //! `pthread_setspecific`). The interface of this differs from the other types
|
6 | 6 | //! of thread-local-storage provided in this crate in that OS-based TLS can only
|
7 |
| -//! get/set pointers, |
| 7 | +//! get/set pointer-sized data, possibly with an associated destructor. |
8 | 8 | //!
|
9 | 9 | //! This module also provides two flavors of TLS. One is intended for static
|
10 | 10 | //! initialization, and does not contain a `Drop` implementation to deallocate
|
|
14 | 14 | //! # Usage
|
15 | 15 | //!
|
16 | 16 | //! This module should likely not be used directly unless other primitives are
|
17 |
| -//! being built on. types such as `thread_local::spawn::Key` are likely much |
| 17 | +//! being built on. Types such as `thread_local::spawn::Key` are likely much |
18 | 18 | //! more useful in practice than this OS-based version which likely requires
|
19 | 19 | //! unsafe code to interoperate with.
|
20 | 20 | //!
|
|
48 | 48 | #![unstable(feature = "thread_local_internals", issue = "none")]
|
49 | 49 | #![allow(dead_code)] // sys isn't exported yet
|
50 | 50 |
|
51 |
| -use crate::ptr; |
52 | 51 | use crate::sync::atomic::{self, AtomicUsize, Ordering};
|
53 |
| -use crate::sys::thread_local as imp; |
| 52 | +use crate::sys::thread_local_key as imp; |
54 | 53 | use crate::sys_common::mutex::Mutex;
|
55 | 54 |
|
56 | 55 | /// A type for TLS keys that are statically allocated.
|
@@ -233,38 +232,6 @@ impl Drop for Key {
|
233 | 232 | }
|
234 | 233 | }
|
235 | 234 |
|
236 |
| -pub unsafe fn register_dtor_fallback(t: *mut u8, dtor: unsafe extern "C" fn(*mut u8)) { |
237 |
| - // The fallback implementation uses a vanilla OS-based TLS key to track |
238 |
| - // the list of destructors that need to be run for this thread. The key |
239 |
| - // then has its own destructor which runs all the other destructors. |
240 |
| - // |
241 |
| - // The destructor for DTORS is a little special in that it has a `while` |
242 |
| - // loop to continuously drain the list of registered destructors. It |
243 |
| - // *should* be the case that this loop always terminates because we |
244 |
| - // provide the guarantee that a TLS key cannot be set after it is |
245 |
| - // flagged for destruction. |
246 |
| - |
247 |
| - static DTORS: StaticKey = StaticKey::new(Some(run_dtors)); |
248 |
| - type List = Vec<(*mut u8, unsafe extern "C" fn(*mut u8))>; |
249 |
| - if DTORS.get().is_null() { |
250 |
| - let v: Box<List> = box Vec::new(); |
251 |
| - DTORS.set(Box::into_raw(v) as *mut u8); |
252 |
| - } |
253 |
| - let list: &mut List = &mut *(DTORS.get() as *mut List); |
254 |
| - list.push((t, dtor)); |
255 |
| - |
256 |
| - unsafe extern "C" fn run_dtors(mut ptr: *mut u8) { |
257 |
| - while !ptr.is_null() { |
258 |
| - let list: Box<List> = Box::from_raw(ptr as *mut List); |
259 |
| - for (ptr, dtor) in list.into_iter() { |
260 |
| - dtor(ptr); |
261 |
| - } |
262 |
| - ptr = DTORS.get(); |
263 |
| - DTORS.set(ptr::null_mut()); |
264 |
| - } |
265 |
| - } |
266 |
| -} |
267 |
| - |
268 | 235 | #[cfg(test)]
|
269 | 236 | mod tests {
|
270 | 237 | use super::{Key, StaticKey};
|
|
0 commit comments