diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2015-01-01 10:19:42 -0800 | 
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2015-03-20 10:56:27 -0700 | 
| commit | 1cc9718fdef63476ffdf3f0bcd74b554b083f378 (patch) | |
| tree | 9ab128b25b8bd688a26897a5b8029672d737140e /src/libstd/sys/common/helper_thread.rs | |
| parent | 46f649c479ce40f3b4590590dda6c2895e8d60f6 (diff) | |
| download | rust-1cc9718fdef63476ffdf3f0bcd74b554b083f378.tar.gz rust-1cc9718fdef63476ffdf3f0bcd74b554b083f378.zip | |
Revert "Revert "std: Re-enable at_exit()""
This reverts commit aec67c2ee0f673ea7b0e21c2fe7e0f26a523d823.
Diffstat (limited to 'src/libstd/sys/common/helper_thread.rs')
| -rw-r--r-- | src/libstd/sys/common/helper_thread.rs | 19 | 
1 files changed, 13 insertions, 6 deletions
| diff --git a/src/libstd/sys/common/helper_thread.rs b/src/libstd/sys/common/helper_thread.rs index 3b5fd5a5714..2a852fbcd57 100644 --- a/src/libstd/sys/common/helper_thread.rs +++ b/src/libstd/sys/common/helper_thread.rs @@ -24,7 +24,6 @@ use prelude::v1::*; use boxed; use cell::UnsafeCell; -use ptr; use rt; use sync::{StaticMutex, StaticCondvar}; use sync::mpsc::{channel, Sender, Receiver}; @@ -97,7 +96,7 @@ impl<M: Send> Helper<M> { { unsafe { let _guard = self.lock.lock().unwrap(); - if !*self.initialized.get() { + if *self.chan.get() as uint == 0 { let (tx, rx) = channel(); *self.chan.get() = boxed::into_raw(box tx); let (receive, send) = helper_signal::new(); @@ -113,8 +112,10 @@ impl<M: Send> Helper<M> { self.cond.notify_one() }); - rt::at_exit(move|| { self.shutdown() }); + rt::at_exit(move || { self.shutdown() }); *self.initialized.get() = true; + } else if *self.chan.get() as uint == 1 { + panic!("cannot continue usage after shutdown"); } } } @@ -129,7 +130,9 @@ impl<M: Send> Helper<M> { // Must send and *then* signal to ensure that the child receives the // message. Otherwise it could wake up and go to sleep before we // send the message. - assert!(!self.chan.get().is_null()); + assert!(*self.chan.get() as uint != 0); + assert!(*self.chan.get() as uint != 1, + "cannot continue usage after shutdown"); (**self.chan.get()).send(msg).unwrap(); helper_signal::signal(*self.signal.get() as helper_signal::signal); } @@ -142,9 +145,13 @@ impl<M: Send> Helper<M> { // returns. let mut guard = self.lock.lock().unwrap(); + let ptr = *self.chan.get(); + if ptr as uint == 1 { + panic!("cannot continue usage after shutdown"); + } // Close the channel by destroying it - let chan: Box<Sender<M>> = Box::from_raw(*self.chan.get()); - *self.chan.get() = ptr::null_mut(); + let chan = Box::from_raw(*self.chan.get()); + *self.chan.get() = 1 as *mut Sender<M>; drop(chan); helper_signal::signal(*self.signal.get() as helper_signal::signal); | 
