@@ -92,23 +92,6 @@ pub mod imp;
92
92
#[ path = "gcc.rs" ] #[ doc( hidden) ]
93
93
pub mod imp;
94
94
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
-
112
95
thread_local ! { static PANICKING : Cell <bool > = Cell :: new( false ) }
113
96
114
97
/// Invoke a closure, capturing the cause of panic if one occurs.
@@ -249,29 +232,6 @@ fn begin_unwind_inner(msg: Box<Any + Send>,
249
232
// First, invoke the default panic handler.
250
233
panicking:: on_panic ( & * msg, file, line) ;
251
234
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.
275
235
if panicking ( ) {
276
236
// If a thread panics while it's already unwinding then we
277
237
// have limited options. Currently our preference is to
@@ -282,34 +242,7 @@ fn begin_unwind_inner(msg: Box<Any + Send>,
282
242
unsafe { intrinsics:: abort ( ) }
283
243
}
284
244
PANICKING . with ( |s| s. set ( true ) ) ;
285
- rust_panic ( msg) ;
286
- }
287
245
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) ;
315
248
}
0 commit comments