1 #![cfg(target_thread_local)]
2 #![unstable(feature = "thread_local_internals", issue = "none")]
4 // Simplify dtor registration by using a list of destructors.
6 use super::{abi, itron::task};
11 static REGISTERED: Cell<bool> = Cell::new(false);
14 static mut DTORS: Vec<(*mut u8, unsafe extern "C" fn(*mut u8))> = Vec::new();
16 pub unsafe fn register_dtor(t: *mut u8, dtor: unsafe extern "C" fn(*mut u8)) {
17 if !REGISTERED.get() {
18 let tid = task::current_task_id_aborting();
19 // Register `tls_dtor` to make sure the TLS destructors are called
20 // for tasks created by other means than `std::thread`
21 unsafe { abi::SOLID_TLS_AddDestructor(tid as i32, tls_dtor) };
25 let list = unsafe { &mut DTORS };
29 pub unsafe fn run_dtors() {
30 let mut list = mem::take(unsafe { &mut DTORS });
31 while !list.is_empty() {
32 for (ptr, dtor) in list {
36 list = mem::take(unsafe { &mut DTORS });
40 unsafe extern "C" fn tls_dtor(_unused: *mut u8) {
41 unsafe { run_dtors() };