@@ -8,7 +8,6 @@ use crate::{
8
8
ErrorKind , ExitHandler , PanicHandler , StartHandler , ThreadPoolBuildError , ThreadPoolBuilder ,
9
9
} ;
10
10
use crossbeam_deque:: { Injector , Steal , Stealer , Worker } ;
11
- use std:: any:: Any ;
12
11
use std:: cell:: Cell ;
13
12
use std:: collections:: hash_map:: DefaultHasher ;
14
13
use std:: fmt;
@@ -332,19 +331,14 @@ impl Registry {
332
331
self . thread_infos . len ( )
333
332
}
334
333
335
- pub ( super ) fn handle_panic ( & self , err : Box < dyn Any + Send > ) {
336
- match self . panic_handler {
337
- Some ( ref handler) => {
338
- // If the customizable panic handler itself panics,
339
- // then we abort.
340
- let abort_guard = unwind:: AbortIfPanic ;
334
+ pub ( super ) fn catch_unwind ( & self , f : impl FnOnce ( ) ) {
335
+ if let Err ( err) = unwind:: halt_unwinding ( f) {
336
+ // If there is no handler, or if that handler itself panics, then we abort.
337
+ let abort_guard = unwind:: AbortIfPanic ;
338
+ if let Some ( ref handler) = self . panic_handler {
341
339
handler ( err) ;
342
340
mem:: forget ( abort_guard) ;
343
341
}
344
- None => {
345
- // Default panic handler aborts.
346
- let _ = unwind:: AbortIfPanic ; // let this drop.
347
- }
348
342
}
349
343
}
350
344
@@ -880,12 +874,7 @@ unsafe fn main_loop(
880
874
881
875
// Inform a user callback that we started a thread.
882
876
if let Some ( ref handler) = registry. start_handler {
883
- match unwind:: halt_unwinding ( || handler ( index) ) {
884
- Ok ( ( ) ) => { }
885
- Err ( err) => {
886
- registry. handle_panic ( err) ;
887
- }
888
- }
877
+ registry. catch_unwind ( || handler ( index) ) ;
889
878
}
890
879
891
880
let my_terminate_latch = & registry. thread_infos [ index] . terminate ;
@@ -908,12 +897,7 @@ unsafe fn main_loop(
908
897
909
898
// Inform a user callback that we exited a thread.
910
899
if let Some ( ref handler) = registry. exit_handler {
911
- match unwind:: halt_unwinding ( || handler ( index) ) {
912
- Ok ( ( ) ) => { }
913
- Err ( err) => {
914
- registry. handle_panic ( err) ;
915
- }
916
- }
900
+ registry. catch_unwind ( || handler ( index) ) ;
917
901
// We're already exiting the thread, there's nothing else to do.
918
902
}
919
903
}
0 commit comments