@@ -505,20 +505,20 @@ impl ThreadLocal<'_, '_> {
505
505
unreachable ! ( )
506
506
} ;
507
507
508
+ let system_tick = * self . last_run ;
508
509
let ( result_tx, result_rx) = std:: sync:: mpsc:: sync_channel ( 1 ) ;
509
- let task = |tls : & mut ThreadLocals | {
510
+ let task = move |tls : & mut ThreadLocals | {
510
511
tls. update_change_tick ( ) ;
511
- let saved = std:: mem:: replace ( & mut tls. last_tick , * self . last_run ) ;
512
+ let saved = std:: mem:: replace ( & mut tls. last_tick , system_tick ) ;
512
513
// we want to propagate to caller instead of panicking in the main thread
513
- let result = std:: panic:: catch_unwind ( std:: panic:: AssertUnwindSafe ( || f ( tls) ) ) ;
514
+ let result =
515
+ std:: panic:: catch_unwind ( std:: panic:: AssertUnwindSafe ( || ( f ( tls) , tls. last_tick ) ) ) ;
514
516
tls. last_tick = saved;
515
517
516
- * self . last_run = tls. last_tick ;
517
518
result_tx. send ( result) . unwrap ( ) ;
518
519
} ;
519
520
520
521
let task: Box < dyn FnOnce ( & mut ThreadLocals ) + Send > = Box :: new ( task) ;
521
-
522
522
let task: Box < dyn FnOnce ( & mut ThreadLocals ) + Send + ' static > =
523
523
// SAFETY: This function will block the calling thread until `f` completes,
524
524
// so any captured references in `f` will remain valid until then.
@@ -531,7 +531,10 @@ impl ThreadLocal<'_, '_> {
531
531
532
532
// Wait to receive result back from the main thread.
533
533
match result_rx. recv ( ) . unwrap ( ) {
534
- Ok ( result) => result,
534
+ Ok ( ( result, last_run) ) => {
535
+ * self . last_run = last_run;
536
+ result
537
+ }
535
538
Err ( payload) => {
536
539
std:: panic:: resume_unwind ( payload) ;
537
540
}
0 commit comments