diff options
| author | Andrea Canciani <ranma42@gmail.com> | 2015-09-22 08:40:15 +0200 |
|---|---|---|
| committer | Andrea Canciani <ranma42@gmail.com> | 2015-09-22 11:02:52 +0200 |
| commit | cbfa61282fc34204b9b66554e06189c2d0b4d085 (patch) | |
| tree | ecb04bd1162bfbab84b33fe7d170f3964bcbd966 /src/libstd/sys/common | |
| parent | f07f4ef74366f70554cb0f2cef590e76bfd55791 (diff) | |
| download | rust-cbfa61282fc34204b9b66554e06189c2d0b4d085.tar.gz rust-cbfa61282fc34204b9b66554e06189c2d0b4d085.zip | |
Simplify on_panic callback handling
The registration of `panicking::on_panic` as a general-purpose callback is overcomplicated and can fail. Instead, invoking it explicitly removes the need for locking and paves the way for further improvements.
Diffstat (limited to 'src/libstd/sys/common')
| -rw-r--r-- | src/libstd/sys/common/unwind/mod.rs | 21 |
1 files changed, 5 insertions, 16 deletions
diff --git a/src/libstd/sys/common/unwind/mod.rs b/src/libstd/sys/common/unwind/mod.rs index 738681c3cfe..47f6bd9315d 100644 --- a/src/libstd/sys/common/unwind/mod.rs +++ b/src/libstd/sys/common/unwind/mod.rs @@ -244,22 +244,12 @@ pub fn begin_unwind<M: Any + Send>(msg: M, file_line: &(&'static str, u32)) -> ! #[inline(never)] #[cold] // this is the slow path, please never inline this fn begin_unwind_inner(msg: Box<Any + Send>, file_line: &(&'static str, u32)) -> ! { - // Make sure the default failure handler is registered before we look at the - // callbacks. We also use a raw sys-based mutex here instead of a - // `std::sync` one as accessing TLS can cause weird recursive problems (and - // we don't need poison checking). - unsafe { - static LOCK: Mutex = Mutex::new(); - static mut INIT: bool = false; - LOCK.lock(); - if !INIT { - register(panicking::on_panic); - INIT = true; - } - LOCK.unlock(); - } + let (file, line) = *file_line; + + // First, invoke the default panic handler. + panicking::on_panic(&*msg, file, line); - // First, invoke call the user-defined callbacks triggered on thread panic. + // Then, invoke call the user-defined callbacks triggered on thread panic. // // By the time that we see a callback has been registered (by reading // MAX_CALLBACKS), the actual callback itself may have not been stored yet, @@ -275,7 +265,6 @@ fn begin_unwind_inner(msg: Box<Any + Send>, 0 => {} n => { let f: Callback = unsafe { mem::transmute(n) }; - let (file, line) = *file_line; f(&*msg, file, line); } } |
