]> git.lizzy.rs Git - rust.git/blobdiff - src/libstd/sys/common/thread_local.rs
std: Leak all statically allocated TLS keys
[rust.git] / src / libstd / sys / common / thread_local.rs
index 9ad38cbaf656f2ca85dd5e5f937b5aef5e11ae4f..370d74cc5e1898da87af6ce1e999025cfb3b833a 100644 (file)
@@ -59,9 +59,7 @@
 use prelude::*;
 
 use kinds::marker;
-use mem;
 use rustrt::exclusive::Exclusive;
-use rustrt;
 use sync::atomic::{mod, AtomicUint};
 use sync::{Once, ONCE_INIT};
 
@@ -174,7 +172,7 @@ pub unsafe fn set(&self, val: *mut u8) { imp::set(self.key(), val) }
     pub unsafe fn destroy(&self) {
         match self.inner.key.swap(0, atomic::SeqCst) {
             0 => {}
-            n => { unregister_key(n as imp::Key); imp::destroy(n as imp::Key) }
+            n => { imp::destroy(n as imp::Key) }
         }
     }
 
@@ -191,10 +189,7 @@ unsafe fn lazy_init(&self) -> uint {
         assert!(key != 0);
         match self.inner.key.compare_and_swap(0, key as uint, atomic::SeqCst) {
             // The CAS succeeded, so we've created the actual key
-            0 => {
-                register_key(key);
-                key as uint
-            }
+            0 => key as uint,
             // If someone beat us to the punch, use their key instead
             n => { imp::destroy(key); n }
         }
@@ -237,34 +232,6 @@ fn drop(&mut self) {
     }
 }
 
-fn init_keys() {
-    let keys = box Exclusive::new(Vec::<imp::Key>::new());
-    unsafe {
-        KEYS = mem::transmute(keys);
-    }
-
-    rustrt::at_exit(proc() unsafe {
-        let keys: Box<Exclusive<Vec<imp::Key>>> = mem::transmute(KEYS);
-        KEYS = 0 as *mut _;
-        let keys = keys.lock();
-        for key in keys.iter() {
-            imp::destroy(*key);
-        }
-    });
-}
-
-fn register_key(key: imp::Key) {
-    INIT_KEYS.doit(init_keys);
-    let mut keys = unsafe { (*KEYS).lock() };
-    keys.push(key);
-}
-
-fn unregister_key(key: imp::Key) {
-    INIT_KEYS.doit(init_keys);
-    let mut keys = unsafe { (*KEYS).lock() };
-    keys.retain(|k| *k != key);
-}
-
 #[cfg(test)]
 mod tests {
     use prelude::*;