@@ -254,7 +254,8 @@ fn cond_set_clock_id<'mir, 'tcx: 'mir>(
254254 set_at_offset ( ecx, cond_op, 8 , clock_id, ecx. machine . layouts . i32 , PTHREAD_COND_T_MIN_SIZE )
255255}
256256
257- /// Try to reacquire the mutex associated with the condition variable after we were signaled.
257+ /// Try to reacquire the mutex associated with the condition variable after we
258+ /// were signaled.
258259fn reacquire_cond_mutex < ' mir , ' tcx : ' mir > (
259260 ecx : & mut MiriEvalContext < ' mir , ' tcx > ,
260261 thread : ThreadId ,
@@ -269,6 +270,17 @@ fn reacquire_cond_mutex<'mir, 'tcx: 'mir>(
269270 Ok ( ( ) )
270271}
271272
273+ /// Reacquire the conditional variable and remove the timeout callback if any
274+ /// was registered.
275+ fn post_cond_signal < ' mir , ' tcx : ' mir > (
276+ ecx : & mut MiriEvalContext < ' mir , ' tcx > ,
277+ thread : ThreadId ,
278+ mutex : MutexId ,
279+ ) -> InterpResult < ' tcx > {
280+ reacquire_cond_mutex ( ecx, thread, mutex) ?;
281+ ecx. unregister_timeout_callback_if_exists ( thread)
282+ }
283+
272284/// Release the mutex associated with the condition variable because we are
273285/// entering the waiting state.
274286fn release_cond_mutex < ' mir , ' tcx : ' mir > (
@@ -648,8 +660,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
648660 let this = self . eval_context_mut ( ) ;
649661 let id = cond_get_or_create_id ( this, cond_op) ?;
650662 if let Some ( ( thread, mutex) ) = this. condvar_signal ( id) {
651- reacquire_cond_mutex ( this, thread, mutex) ?;
652- this. unregister_timeout_callback_if_exists ( thread) ?;
663+ post_cond_signal ( this, thread, mutex) ?;
653664 }
654665
655666 Ok ( 0 )
@@ -660,8 +671,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
660671 let id = cond_get_or_create_id ( this, cond_op) ?;
661672
662673 while let Some ( ( thread, mutex) ) = this. condvar_signal ( id) {
663- reacquire_cond_mutex ( this, thread, mutex) ?;
664- this. unregister_timeout_callback_if_exists ( thread) ?;
674+ post_cond_signal ( this, thread, mutex) ?;
665675 }
666676
667677 Ok ( 0 )
@@ -730,21 +740,22 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
730740 } else if clock_id == this. eval_libc_i32 ( "CLOCK_MONOTONIC" ) ? {
731741 Time :: Monotonic ( this. machine . time_anchor . checked_add ( duration) . unwrap ( ) )
732742 } else {
733- throw_ub_format ! ( "Unsupported clock id." ) ;
743+ throw_unsup_format ! ( "Unsupported clock id." ) ;
734744 } ;
735745
736746 // Register the timeout callback.
737747 this. register_timeout_callback (
738748 active_thread,
739749 timeout_time,
740750 Box :: new ( move |ecx| {
741- // Try to reacquire the mutex.
751+ // We are not waiting for the condvar any more, wait for the
752+ // mutex instead.
742753 reacquire_cond_mutex ( ecx, active_thread, mutex_id) ?;
743754
744755 // Remove the thread from the conditional variable.
745756 ecx. condvar_remove_waiter ( id, active_thread) ;
746757
747- // Set the timeout value.
758+ // Set the return value: we timed out .
748759 let timeout = ecx. eval_libc_i32 ( "ETIMEDOUT" ) ?;
749760 ecx. write_scalar ( Scalar :: from_i32 ( timeout) , dest) ?;
750761
0 commit comments