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
This commit is contained in:
commit
5f9741e62d
1 changed files with 2 additions and 35 deletions
|
@ -59,9 +59,7 @@
|
||||||
use prelude::*;
|
use prelude::*;
|
||||||
|
|
||||||
use kinds::marker;
|
use kinds::marker;
|
||||||
use mem;
|
|
||||||
use rustrt::exclusive::Exclusive;
|
use rustrt::exclusive::Exclusive;
|
||||||
use rustrt;
|
|
||||||
use sync::atomic::{mod, AtomicUint};
|
use sync::atomic::{mod, AtomicUint};
|
||||||
use sync::{Once, ONCE_INIT};
|
use sync::{Once, ONCE_INIT};
|
||||||
|
|
||||||
|
@ -174,7 +172,7 @@ impl StaticKey {
|
||||||
pub unsafe fn destroy(&self) {
|
pub unsafe fn destroy(&self) {
|
||||||
match self.inner.key.swap(0, atomic::SeqCst) {
|
match self.inner.key.swap(0, atomic::SeqCst) {
|
||||||
0 => {}
|
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 @@ impl StaticKey {
|
||||||
assert!(key != 0);
|
assert!(key != 0);
|
||||||
match self.inner.key.compare_and_swap(0, key as uint, atomic::SeqCst) {
|
match self.inner.key.compare_and_swap(0, key as uint, atomic::SeqCst) {
|
||||||
// The CAS succeeded, so we've created the actual key
|
// The CAS succeeded, so we've created the actual key
|
||||||
0 => {
|
0 => key as uint,
|
||||||
register_key(key);
|
|
||||||
key as uint
|
|
||||||
}
|
|
||||||
// If someone beat us to the punch, use their key instead
|
// If someone beat us to the punch, use their key instead
|
||||||
n => { imp::destroy(key); n }
|
n => { imp::destroy(key); n }
|
||||||
}
|
}
|
||||||
|
@ -237,34 +232,6 @@ impl Drop for Key {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use prelude::*;
|
use prelude::*;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue