@@ -3,7 +3,7 @@ use std::time::Duration;
3
3
use rustc_target:: abi:: Size ;
4
4
5
5
use crate :: concurrency:: init_once:: InitOnceStatus ;
6
- use crate :: concurrency:: sync:: CondvarLock ;
6
+ use crate :: concurrency:: sync:: { CondvarLock , RwLockMode } ;
7
7
use crate :: concurrency:: thread:: MachineCallback ;
8
8
use crate :: * ;
9
9
@@ -19,23 +19,24 @@ trait EvalContextExtPriv<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
19
19
& mut self ,
20
20
thread : ThreadId ,
21
21
lock : RwLockId ,
22
- shared : bool ,
22
+ mode : RwLockMode ,
23
23
) -> InterpResult < ' tcx > {
24
24
let this = self . eval_context_mut ( ) ;
25
25
this. unblock_thread ( thread) ;
26
26
27
- if shared {
28
- if this. rwlock_is_write_locked ( lock) {
29
- this. rwlock_enqueue_and_block_reader ( lock, thread) ;
30
- } else {
31
- this. rwlock_reader_lock ( lock, thread) ;
32
- }
33
- } else {
34
- if this. rwlock_is_locked ( lock) {
35
- this. rwlock_enqueue_and_block_writer ( lock, thread) ;
36
- } else {
37
- this. rwlock_writer_lock ( lock, thread) ;
38
- }
27
+ match mode {
28
+ RwLockMode :: Shared =>
29
+ if this. rwlock_is_write_locked ( lock) {
30
+ this. rwlock_enqueue_and_block_reader ( lock, thread) ;
31
+ } else {
32
+ this. rwlock_reader_lock ( lock, thread) ;
33
+ } ,
34
+ RwLockMode :: Exclusive =>
35
+ if this. rwlock_is_locked ( lock) {
36
+ this. rwlock_enqueue_and_block_writer ( lock, thread) ;
37
+ } else {
38
+ this. rwlock_writer_lock ( lock, thread) ;
39
+ } ,
39
40
}
40
41
41
42
Ok ( ( ) )
@@ -385,14 +386,19 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
385
386
} ;
386
387
387
388
let shared_mode = 0x1 ; // CONDITION_VARIABLE_LOCKMODE_SHARED is not in std
388
- let shared = flags == shared_mode;
389
+ let mode = if flags == 0 {
390
+ RwLockMode :: Exclusive
391
+ } else if flags == shared_mode {
392
+ RwLockMode :: Shared
393
+ } else {
394
+ throw_unsup_format ! ( "unsupported `Flags` {flags} in `SleepConditionVariableSRW`" ) ;
395
+ } ;
389
396
390
397
let active_thread = this. get_active_thread ( ) ;
391
398
392
- let was_locked = if shared {
393
- this. rwlock_reader_unlock ( lock_id, active_thread)
394
- } else {
395
- this. rwlock_writer_unlock ( lock_id, active_thread)
399
+ let was_locked = match mode {
400
+ RwLockMode :: Shared => this. rwlock_reader_unlock ( lock_id, active_thread) ,
401
+ RwLockMode :: Exclusive => this. rwlock_writer_unlock ( lock_id, active_thread) ,
396
402
} ;
397
403
398
404
if !was_locked {
@@ -402,27 +408,27 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
402
408
}
403
409
404
410
this. block_thread ( active_thread) ;
405
- this. condvar_wait ( condvar_id, active_thread, CondvarLock :: RwLock { id : lock_id, shared } ) ;
411
+ this. condvar_wait ( condvar_id, active_thread, CondvarLock :: RwLock { id : lock_id, mode } ) ;
406
412
407
413
if let Some ( timeout_time) = timeout_time {
408
414
struct Callback < ' tcx > {
409
415
thread : ThreadId ,
410
416
condvar_id : CondvarId ,
411
417
lock_id : RwLockId ,
412
- shared : bool ,
418
+ mode : RwLockMode ,
413
419
dest : PlaceTy < ' tcx , Provenance > ,
414
420
}
415
421
416
422
impl < ' tcx > VisitTags for Callback < ' tcx > {
417
423
fn visit_tags ( & self , visit : & mut dyn FnMut ( SbTag ) ) {
418
- let Callback { thread : _, condvar_id : _, lock_id : _, shared : _, dest } = self ;
424
+ let Callback { thread : _, condvar_id : _, lock_id : _, mode : _, dest } = self ;
419
425
dest. visit_tags ( visit) ;
420
426
}
421
427
}
422
428
423
429
impl < ' mir , ' tcx : ' mir > MachineCallback < ' mir , ' tcx > for Callback < ' tcx > {
424
430
fn call ( & self , this : & mut MiriInterpCx < ' mir , ' tcx > ) -> InterpResult < ' tcx > {
425
- this. reacquire_cond_lock ( self . thread , self . lock_id , self . shared ) ?;
431
+ this. reacquire_cond_lock ( self . thread , self . lock_id , self . mode ) ?;
426
432
427
433
this. condvar_remove_waiter ( self . condvar_id , self . thread ) ;
428
434
@@ -440,7 +446,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
440
446
thread : active_thread,
441
447
condvar_id,
442
448
lock_id,
443
- shared ,
449
+ mode ,
444
450
dest : dest. clone ( ) ,
445
451
} ) ,
446
452
) ;
@@ -454,8 +460,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
454
460
let condvar_id = this. condvar_get_or_create_id ( condvar_op, CONDVAR_ID_OFFSET ) ?;
455
461
456
462
if let Some ( ( thread, lock) ) = this. condvar_signal ( condvar_id) {
457
- if let CondvarLock :: RwLock { id, shared } = lock {
458
- this. reacquire_cond_lock ( thread, id, shared ) ?;
463
+ if let CondvarLock :: RwLock { id, mode } = lock {
464
+ this. reacquire_cond_lock ( thread, id, mode ) ?;
459
465
this. unregister_timeout_callback_if_exists ( thread) ;
460
466
} else {
461
467
panic ! ( "mutexes should not exist on windows" ) ;
@@ -473,8 +479,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
473
479
let condvar_id = this. condvar_get_or_create_id ( condvar_op, CONDVAR_ID_OFFSET ) ?;
474
480
475
481
while let Some ( ( thread, lock) ) = this. condvar_signal ( condvar_id) {
476
- if let CondvarLock :: RwLock { id, shared } = lock {
477
- this. reacquire_cond_lock ( thread, id, shared ) ?;
482
+ if let CondvarLock :: RwLock { id, mode } = lock {
483
+ this. reacquire_cond_lock ( thread, id, mode ) ?;
478
484
this. unregister_timeout_callback_if_exists ( thread) ;
479
485
} else {
480
486
panic ! ( "mutexes should not exist on windows" ) ;
0 commit comments