Skip to content

Commit 5f9741e

Browse files
committed
auto merge of #19285 : alexcrichton/rust/issue-19280, r=aturon
It turns out that rustrt::at_exit() doesn't actually occur after all pthread threads have exited (nor does atexit()), so there's not actually a known point at which we can deallocate these keys. It's not super critical that we do so, however, because we're about to exit anyway! Closes #19280
2 parents 5acb97a + a4b1ac5 commit 5f9741e

File tree

1 file changed

+2
-35
lines changed

1 file changed

+2
-35
lines changed

src/libstd/sys/common/thread_local.rs

+2-35
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,7 @@
5959
use prelude::*;
6060

6161
use kinds::marker;
62-
use mem;
6362
use rustrt::exclusive::Exclusive;
64-
use rustrt;
6563
use sync::atomic::{mod, AtomicUint};
6664
use sync::{Once, ONCE_INIT};
6765

@@ -174,7 +172,7 @@ impl StaticKey {
174172
pub unsafe fn destroy(&self) {
175173
match self.inner.key.swap(0, atomic::SeqCst) {
176174
0 => {}
177-
n => { unregister_key(n as imp::Key); imp::destroy(n as imp::Key) }
175+
n => { imp::destroy(n as imp::Key) }
178176
}
179177
}
180178

@@ -191,10 +189,7 @@ impl StaticKey {
191189
assert!(key != 0);
192190
match self.inner.key.compare_and_swap(0, key as uint, atomic::SeqCst) {
193191
// The CAS succeeded, so we've created the actual key
194-
0 => {
195-
register_key(key);
196-
key as uint
197-
}
192+
0 => key as uint,
198193
// If someone beat us to the punch, use their key instead
199194
n => { imp::destroy(key); n }
200195
}
@@ -237,34 +232,6 @@ impl Drop for Key {
237232
}
238233
}
239234

240-
fn init_keys() {
241-
let keys = box Exclusive::new(Vec::<imp::Key>::new());
242-
unsafe {
243-
KEYS = mem::transmute(keys);
244-
}
245-
246-
rustrt::at_exit(proc() unsafe {
247-
let keys: Box<Exclusive<Vec<imp::Key>>> = mem::transmute(KEYS);
248-
KEYS = 0 as *mut _;
249-
let keys = keys.lock();
250-
for key in keys.iter() {
251-
imp::destroy(*key);
252-
}
253-
});
254-
}
255-
256-
fn register_key(key: imp::Key) {
257-
INIT_KEYS.doit(init_keys);
258-
let mut keys = unsafe { (*KEYS).lock() };
259-
keys.push(key);
260-
}
261-
262-
fn unregister_key(key: imp::Key) {
263-
INIT_KEYS.doit(init_keys);
264-
let mut keys = unsafe { (*KEYS).lock() };
265-
keys.retain(|k| *k != key);
266-
}
267-
268235
#[cfg(test)]
269236
mod tests {
270237
use prelude::*;

0 commit comments

Comments
 (0)