Skip to content

Commit c6d277a

Browse files
committed
Remove unwind::register
The `register` function is unstable and it is not used anymore, hence it can be removed (together with the now-unused `Callback` type and `static` variables).
1 parent cbfa612 commit c6d277a

File tree

1 file changed

+2
-69
lines changed
  • src/libstd/sys/common/unwind

1 file changed

+2
-69
lines changed

src/libstd/sys/common/unwind/mod.rs

+2-69
Original file line numberDiff line numberDiff line change
@@ -92,23 +92,6 @@ pub mod imp;
9292
#[path = "gcc.rs"] #[doc(hidden)]
9393
pub mod imp;
9494

95-
pub type Callback = fn(msg: &(Any + Send), file: &'static str, line: u32);
96-
97-
// Variables used for invoking callbacks when a thread starts to unwind.
98-
//
99-
// For more information, see below.
100-
const MAX_CALLBACKS: usize = 16;
101-
static CALLBACKS: [atomic::AtomicUsize; MAX_CALLBACKS] =
102-
[atomic::AtomicUsize::new(0), atomic::AtomicUsize::new(0),
103-
atomic::AtomicUsize::new(0), atomic::AtomicUsize::new(0),
104-
atomic::AtomicUsize::new(0), atomic::AtomicUsize::new(0),
105-
atomic::AtomicUsize::new(0), atomic::AtomicUsize::new(0),
106-
atomic::AtomicUsize::new(0), atomic::AtomicUsize::new(0),
107-
atomic::AtomicUsize::new(0), atomic::AtomicUsize::new(0),
108-
atomic::AtomicUsize::new(0), atomic::AtomicUsize::new(0),
109-
atomic::AtomicUsize::new(0), atomic::AtomicUsize::new(0)];
110-
static CALLBACK_CNT: atomic::AtomicUsize = atomic::AtomicUsize::new(0);
111-
11295
thread_local! { static PANICKING: Cell<bool> = Cell::new(false) }
11396

11497
/// Invoke a closure, capturing the cause of panic if one occurs.
@@ -249,29 +232,6 @@ fn begin_unwind_inner(msg: Box<Any + Send>,
249232
// First, invoke the default panic handler.
250233
panicking::on_panic(&*msg, file, line);
251234

252-
// Then, invoke call the user-defined callbacks triggered on thread panic.
253-
//
254-
// By the time that we see a callback has been registered (by reading
255-
// MAX_CALLBACKS), the actual callback itself may have not been stored yet,
256-
// so we just chalk it up to a race condition and move on to the next
257-
// callback. Additionally, CALLBACK_CNT may briefly be higher than
258-
// MAX_CALLBACKS, so we're sure to clamp it as necessary.
259-
let callbacks = {
260-
let amt = CALLBACK_CNT.load(Ordering::SeqCst);
261-
&CALLBACKS[..cmp::min(amt, MAX_CALLBACKS)]
262-
};
263-
for cb in callbacks {
264-
match cb.load(Ordering::SeqCst) {
265-
0 => {}
266-
n => {
267-
let f: Callback = unsafe { mem::transmute(n) };
268-
f(&*msg, file, line);
269-
}
270-
}
271-
};
272-
273-
// Now that we've run all the necessary unwind callbacks, we actually
274-
// perform the unwinding.
275235
if panicking() {
276236
// If a thread panics while it's already unwinding then we
277237
// have limited options. Currently our preference is to
@@ -282,34 +242,7 @@ fn begin_unwind_inner(msg: Box<Any + Send>,
282242
unsafe { intrinsics::abort() }
283243
}
284244
PANICKING.with(|s| s.set(true));
285-
rust_panic(msg);
286-
}
287245

288-
/// Register a callback to be invoked when a thread unwinds.
289-
///
290-
/// This is an unsafe and experimental API which allows for an arbitrary
291-
/// callback to be invoked when a thread panics. This callback is invoked on both
292-
/// the initial unwinding and a double unwinding if one occurs. Additionally,
293-
/// the local `Thread` will be in place for the duration of the callback, and
294-
/// the callback must ensure that it remains in place once the callback returns.
295-
///
296-
/// Only a limited number of callbacks can be registered, and this function
297-
/// returns whether the callback was successfully registered or not. It is not
298-
/// currently possible to unregister a callback once it has been registered.
299-
pub unsafe fn register(f: Callback) -> bool {
300-
match CALLBACK_CNT.fetch_add(1, Ordering::SeqCst) {
301-
// The invocation code has knowledge of this window where the count has
302-
// been incremented, but the callback has not been stored. We're
303-
// guaranteed that the slot we're storing into is 0.
304-
n if n < MAX_CALLBACKS => {
305-
let prev = CALLBACKS[n].swap(mem::transmute(f), Ordering::SeqCst);
306-
rtassert!(prev == 0);
307-
true
308-
}
309-
// If we accidentally bumped the count too high, pull it back.
310-
_ => {
311-
CALLBACK_CNT.store(MAX_CALLBACKS, Ordering::SeqCst);
312-
false
313-
}
314-
}
246+
// Finally, perform the unwinding.
247+
rust_panic(msg);
315248
}

0 commit comments

Comments
 (0)