@@ -422,7 +422,9 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
422422 mutex_ref: MutexRef ,
423423 retval_dest: Option <( Scalar , MPlaceTy <' tcx>) >,
424424 }
425- @unblock = |this| {
425+ |this, unblock: UnblockKind | {
426+ assert_eq!( unblock, UnblockKind :: Ready ) ;
427+
426428 assert!( !this. mutex_is_locked( & mutex_ref) ) ;
427429 this. mutex_lock( & mutex_ref) ;
428430
@@ -538,7 +540,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
538540 retval: Scalar ,
539541 dest: MPlaceTy <' tcx>,
540542 }
541- @unblock = |this| {
543+ |this, unblock: UnblockKind | {
544+ assert_eq!( unblock, UnblockKind :: Ready ) ;
542545 this. rwlock_reader_lock( id) ;
543546 this. write_scalar( retval, & dest) ?;
544547 interp_ok( ( ) )
@@ -623,7 +626,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
623626 retval: Scalar ,
624627 dest: MPlaceTy <' tcx>,
625628 }
626- @unblock = |this| {
629+ |this, unblock: UnblockKind | {
630+ assert_eq!( unblock, UnblockKind :: Ready ) ;
627631 this. rwlock_writer_lock( id) ;
628632 this. write_scalar( retval, & dest) ?;
629633 interp_ok( ( ) )
@@ -677,25 +681,29 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
677681 retval_timeout: Scalar ,
678682 dest: MPlaceTy <' tcx>,
679683 }
680- @unblock = |this| {
681- // The condvar was signaled. Make sure we get the clock for that.
682- if let Some ( data_race) = & this. machine. data_race {
683- data_race. acquire_clock(
684- & this. machine. sync. condvars[ condvar] . clock,
685- & this. machine. threads,
686- ) ;
684+ |this, unblock: UnblockKind | {
685+ match unblock {
686+ UnblockKind :: Ready => {
687+ // The condvar was signaled. Make sure we get the clock for that.
688+ if let Some ( data_race) = & this. machine. data_race {
689+ data_race. acquire_clock(
690+ & this. machine. sync. condvars[ condvar] . clock,
691+ & this. machine. threads,
692+ ) ;
693+ }
694+ // Try to acquire the mutex.
695+ // The timeout only applies to the first wait (until the signal), not for mutex acquisition.
696+ this. condvar_reacquire_mutex( & mutex_ref, retval_succ, dest)
697+ }
698+ UnblockKind :: TimedOut => {
699+ // We have to remove the waiter from the queue again.
700+ let thread = this. active_thread( ) ;
701+ let waiters = & mut this. machine. sync. condvars[ condvar] . waiters;
702+ waiters. retain( |waiter| * waiter != thread) ;
703+ // Now get back the lock.
704+ this. condvar_reacquire_mutex( & mutex_ref, retval_timeout, dest)
705+ }
687706 }
688- // Try to acquire the mutex.
689- // The timeout only applies to the first wait (until the signal), not for mutex acquisition.
690- this. condvar_reacquire_mutex( & mutex_ref, retval_succ, dest)
691- }
692- @timeout = |this| {
693- // We have to remove the waiter from the queue again.
694- let thread = this. active_thread( ) ;
695- let waiters = & mut this. machine. sync. condvars[ condvar] . waiters;
696- waiters. retain( |waiter| * waiter != thread) ;
697- // Now get back the lock.
698- this. condvar_reacquire_mutex( & mutex_ref, retval_timeout, dest)
699707 }
700708 ) ,
701709 ) ;
@@ -752,25 +760,29 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
752760 dest: MPlaceTy <' tcx>,
753761 errno_timeout: IoError ,
754762 }
755- @unblock = |this| {
756- let futex = futex_ref. 0 . borrow( ) ;
757- // Acquire the clock of the futex.
758- if let Some ( data_race) = & this. machine. data_race {
759- data_race. acquire_clock( & futex. clock, & this. machine. threads) ;
763+ |this, unblock: UnblockKind | {
764+ match unblock {
765+ UnblockKind :: Ready => {
766+ let futex = futex_ref. 0 . borrow( ) ;
767+ // Acquire the clock of the futex.
768+ if let Some ( data_race) = & this. machine. data_race {
769+ data_race. acquire_clock( & futex. clock, & this. machine. threads) ;
770+ }
771+ // Write the return value.
772+ this. write_scalar( retval_succ, & dest) ?;
773+ interp_ok( ( ) )
774+ } ,
775+ UnblockKind :: TimedOut => {
776+ // Remove the waiter from the futex.
777+ let thread = this. active_thread( ) ;
778+ let mut futex = futex_ref. 0 . borrow_mut( ) ;
779+ futex. waiters. retain( |waiter| waiter. thread != thread) ;
780+ // Set errno and write return value.
781+ this. set_last_error( errno_timeout) ?;
782+ this. write_scalar( retval_timeout, & dest) ?;
783+ interp_ok( ( ) )
784+ } ,
760785 }
761- // Write the return value.
762- this. write_scalar( retval_succ, & dest) ?;
763- interp_ok( ( ) )
764- }
765- @timeout = |this| {
766- // Remove the waiter from the futex.
767- let thread = this. active_thread( ) ;
768- let mut futex = futex_ref. 0 . borrow_mut( ) ;
769- futex. waiters. retain( |waiter| waiter. thread != thread) ;
770- // Set errno and write return value.
771- this. set_last_error( errno_timeout) ?;
772- this. write_scalar( retval_timeout, & dest) ?;
773- interp_ok( ( ) )
774786 }
775787 ) ,
776788 ) ;
0 commit comments