@@ -204,7 +204,7 @@ pub(super) trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
204
204
this. mutex_enqueue_and_block ( mutex_ref, Some ( ( retval, dest) ) ) ;
205
205
} else {
206
206
// We can have it right now!
207
- this. mutex_lock ( & mutex_ref) ;
207
+ this. mutex_lock ( & mutex_ref) ? ;
208
208
// Don't forget to write the return value.
209
209
this. write_scalar ( retval, & dest) ?;
210
210
}
@@ -338,7 +338,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
338
338
}
339
339
340
340
/// Lock by setting the mutex owner and increasing the lock count.
341
- fn mutex_lock ( & mut self , mutex_ref : & MutexRef ) {
341
+ fn mutex_lock ( & mut self , mutex_ref : & MutexRef ) -> InterpResult < ' tcx > {
342
342
let this = self . eval_context_mut ( ) ;
343
343
let thread = this. active_thread ( ) ;
344
344
let mut mutex = mutex_ref. 0 . borrow_mut ( ) ;
@@ -352,9 +352,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
352
352
mutex. owner = Some ( thread) ;
353
353
}
354
354
mutex. lock_count = mutex. lock_count . strict_add ( 1 ) ;
355
- if let Some ( data_race) = this. machine . data_race . as_vclocks_ref ( ) {
356
- data_race. acquire_clock ( & mutex. clock , & this. machine . threads ) ;
357
- }
355
+ this. acquire_clock ( & mutex. clock ) ?;
356
+ interp_ok ( ( ) )
358
357
}
359
358
360
359
/// Try unlocking by decreasing the lock count and returning the old lock
@@ -377,11 +376,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
377
376
// The mutex is completely unlocked. Try transferring ownership
378
377
// to another thread.
379
378
380
- if let Some ( data_race) = this. machine . data_race . as_vclocks_ref ( ) {
381
- data_race. release_clock ( & this. machine . threads , |clock| {
382
- mutex. clock . clone_from ( clock)
383
- } ) ;
384
- }
379
+ this. release_clock ( |clock| mutex. clock . clone_from ( clock) ) ?;
385
380
let thread_id = mutex. queue . pop_front ( ) ;
386
381
// We need to drop our mutex borrow before unblock_thread
387
382
// because it will be borrowed again in the unblock callback.
@@ -425,7 +420,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
425
420
assert_eq!( unblock, UnblockKind :: Ready ) ;
426
421
427
422
assert!( mutex_ref. owner( ) . is_none( ) ) ;
428
- this. mutex_lock( & mutex_ref) ;
423
+ this. mutex_lock( & mutex_ref) ? ;
429
424
430
425
if let Some ( ( retval, dest) ) = retval_dest {
431
426
this. write_scalar( retval, & dest) ?;
@@ -439,17 +434,16 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
439
434
440
435
/// Read-lock the lock by adding the `reader` the list of threads that own
441
436
/// this lock.
442
- fn rwlock_reader_lock ( & mut self , rwlock_ref : & RwLockRef ) {
437
+ fn rwlock_reader_lock ( & mut self , rwlock_ref : & RwLockRef ) -> InterpResult < ' tcx > {
443
438
let this = self . eval_context_mut ( ) ;
444
439
let thread = this. active_thread ( ) ;
445
440
trace ! ( "rwlock_reader_lock: now also held (one more time) by {:?}" , thread) ;
446
441
let mut rwlock = rwlock_ref. 0 . borrow_mut ( ) ;
447
442
assert ! ( !rwlock. is_write_locked( ) , "the lock is write locked" ) ;
448
443
let count = rwlock. readers . entry ( thread) . or_insert ( 0 ) ;
449
444
* count = count. strict_add ( 1 ) ;
450
- if let Some ( data_race) = this. machine . data_race . as_vclocks_ref ( ) {
451
- data_race. acquire_clock ( & rwlock. clock_unlocked , & this. machine . threads ) ;
452
- }
445
+ this. acquire_clock ( & rwlock. clock_unlocked ) ?;
446
+ interp_ok ( ( ) )
453
447
}
454
448
455
449
/// Try read-unlock the lock for the current threads and potentially give the lock to a new owner.
@@ -472,12 +466,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
472
466
}
473
467
Entry :: Vacant ( _) => return interp_ok ( false ) , // we did not even own this lock
474
468
}
475
- if let Some ( data_race) = this. machine . data_race . as_vclocks_ref ( ) {
476
- // Add this to the shared-release clock of all concurrent readers.
477
- data_race. release_clock ( & this. machine . threads , |clock| {
478
- rwlock. clock_current_readers . join ( clock)
479
- } ) ;
480
- }
469
+ // Add this to the shared-release clock of all concurrent readers.
470
+ this. release_clock ( |clock| rwlock. clock_current_readers . join ( clock) ) ?;
481
471
482
472
// The thread was a reader. If the lock is not held any more, give it to a writer.
483
473
if rwlock. is_locked ( ) . not ( ) {
@@ -521,7 +511,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
521
511
}
522
512
|this, unblock: UnblockKind | {
523
513
assert_eq!( unblock, UnblockKind :: Ready ) ;
524
- this. rwlock_reader_lock( & rwlock_ref) ;
514
+ this. rwlock_reader_lock( & rwlock_ref) ? ;
525
515
this. write_scalar( retval, & dest) ?;
526
516
interp_ok( ( ) )
527
517
}
@@ -531,17 +521,16 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
531
521
532
522
/// Lock by setting the writer that owns the lock.
533
523
#[ inline]
534
- fn rwlock_writer_lock ( & mut self , rwlock_ref : & RwLockRef ) {
524
+ fn rwlock_writer_lock ( & mut self , rwlock_ref : & RwLockRef ) -> InterpResult < ' tcx > {
535
525
let this = self . eval_context_mut ( ) ;
536
526
let thread = this. active_thread ( ) ;
537
527
trace ! ( "rwlock_writer_lock: now held by {:?}" , thread) ;
538
528
539
529
let mut rwlock = rwlock_ref. 0 . borrow_mut ( ) ;
540
530
assert ! ( !rwlock. is_locked( ) , "the rwlock is already locked" ) ;
541
531
rwlock. writer = Some ( thread) ;
542
- if let Some ( data_race) = this. machine . data_race . as_vclocks_ref ( ) {
543
- data_race. acquire_clock ( & rwlock. clock_unlocked , & this. machine . threads ) ;
544
- }
532
+ this. acquire_clock ( & rwlock. clock_unlocked ) ?;
533
+ interp_ok ( ( ) )
545
534
}
546
535
547
536
/// Try to unlock an rwlock held by the current thread.
@@ -559,11 +548,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
559
548
rwlock. writer = None ;
560
549
trace ! ( "rwlock_writer_unlock: unlocked by {:?}" , thread) ;
561
550
// Record release clock for next lock holder.
562
- if let Some ( data_race) = this. machine . data_race . as_vclocks_ref ( ) {
563
- data_race. release_clock ( & this. machine . threads , |clock| {
564
- rwlock. clock_unlocked . clone_from ( clock)
565
- } ) ;
566
- }
551
+ this. release_clock ( |clock| rwlock. clock_unlocked . clone_from ( clock) ) ?;
567
552
568
553
// The thread was a writer.
569
554
//
@@ -613,7 +598,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
613
598
}
614
599
|this, unblock: UnblockKind | {
615
600
assert_eq!( unblock, UnblockKind :: Ready ) ;
616
- this. rwlock_writer_lock( & rwlock_ref) ;
601
+ this. rwlock_writer_lock( & rwlock_ref) ? ;
617
602
this. write_scalar( retval, & dest) ?;
618
603
interp_ok( ( ) )
619
604
}
@@ -663,12 +648,9 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
663
648
match unblock {
664
649
UnblockKind :: Ready => {
665
650
// The condvar was signaled. Make sure we get the clock for that.
666
- if let Some ( data_race) = this. machine. data_race. as_vclocks_ref( ) {
667
- data_race. acquire_clock(
651
+ this. acquire_clock(
668
652
& condvar_ref. 0 . borrow( ) . clock,
669
- & this. machine. threads,
670
- ) ;
671
- }
653
+ ) ?;
672
654
// Try to acquire the mutex.
673
655
// The timeout only applies to the first wait (until the signal), not for mutex acquisition.
674
656
this. condvar_reacquire_mutex( mutex_ref, retval_succ, dest)
@@ -695,9 +677,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
695
677
let mut condvar = condvar_ref. 0 . borrow_mut ( ) ;
696
678
697
679
// Each condvar signal happens-before the end of the condvar wake
698
- if let Some ( data_race) = this. machine . data_race . as_vclocks_ref ( ) {
699
- data_race. release_clock ( & this. machine . threads , |clock| condvar. clock . clone_from ( clock) ) ;
700
- }
680
+ this. release_clock ( |clock| condvar. clock . clone_from ( clock) ) ?;
701
681
let Some ( waiter) = condvar. waiters . pop_front ( ) else {
702
682
return interp_ok ( false ) ;
703
683
} ;
@@ -736,9 +716,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
736
716
UnblockKind :: Ready => {
737
717
let futex = futex_ref. 0 . borrow( ) ;
738
718
// Acquire the clock of the futex.
739
- if let Some ( data_race) = this. machine. data_race. as_vclocks_ref( ) {
740
- data_race. acquire_clock( & futex. clock, & this. machine. threads) ;
741
- }
719
+ this. acquire_clock( & futex. clock) ?;
742
720
} ,
743
721
UnblockKind :: TimedOut => {
744
722
// Remove the waiter from the futex.
@@ -766,9 +744,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
766
744
let mut futex = futex_ref. 0 . borrow_mut ( ) ;
767
745
768
746
// Each futex-wake happens-before the end of the futex wait
769
- if let Some ( data_race) = this. machine . data_race . as_vclocks_ref ( ) {
770
- data_race. release_clock ( & this. machine . threads , |clock| futex. clock . clone_from ( clock) ) ;
771
- }
747
+ this. release_clock ( |clock| futex. clock . clone_from ( clock) ) ?;
772
748
773
749
// Remove `count` of the threads in the queue that match any of the bits in the bitset.
774
750
// We collect all of them before unblocking because the unblock callback may access the
0 commit comments