1 #![cfg(target_thread_local)]
2 #![unstable(feature = "thread_local_internals", issue = "none")]
4 // Simplify dtor registration by using a list of destructors.
5 // The this solution works like the implementation of macOS and
6 // doesn't additional OS support
12 static DTORS: Cell<*mut List> = Cell::new(ptr::null_mut());
14 type List = Vec<(*mut u8, unsafe extern "C" fn(*mut u8))>;
16 pub unsafe fn register_dtor(t: *mut u8, dtor: unsafe extern "C" fn(*mut u8)) {
17 if DTORS.get().is_null() {
18 let v: Box<List> = box Vec::new();
19 DTORS.set(Box::into_raw(v));
22 let list: &mut List = &mut *DTORS.get();
26 // every thread call this function to run through all possible destructors
27 pub unsafe fn run_dtors() {
28 let mut ptr = DTORS.replace(ptr::null_mut());
29 while !ptr.is_null() {
30 let list = Box::from_raw(ptr);
31 for (ptr, dtor) in list.into_iter() {
34 ptr = DTORS.replace(ptr::null_mut());