@@ -170,9 +170,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
170
170
mutex. owner = None ;
171
171
// The mutex is completely unlocked. Try transfering ownership
172
172
// to another thread.
173
- if let Some ( new_owner) = this. mutex_dequeue_and_unblock ( id) {
174
- this. mutex_lock ( id, new_owner) ;
175
- }
173
+ this. mutex_dequeue_and_lock ( id) ;
176
174
}
177
175
Ok ( Some ( old_lock_count) )
178
176
} else {
@@ -182,7 +180,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
182
180
}
183
181
184
182
#[ inline]
185
- /// Put the thread into the queue waiting for the lock .
183
+ /// Put the thread into the queue waiting for the mutex .
186
184
fn mutex_enqueue_and_block ( & mut self , id : MutexId , thread : ThreadId ) {
187
185
let this = self . eval_context_mut ( ) ;
188
186
assert ! ( this. mutex_is_locked( id) , "queing on unlocked mutex" ) ;
@@ -191,14 +189,16 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
191
189
}
192
190
193
191
#[ inline]
194
- /// Take a thread out of the queue waiting for the lock.
195
- fn mutex_dequeue_and_unblock ( & mut self , id : MutexId ) -> Option < ThreadId > {
192
+ /// Take a thread out of the queue waiting for the mutex, and lock
193
+ /// the mutex for it. Returns `true` if some thread has the mutex now.
194
+ fn mutex_dequeue_and_lock ( & mut self , id : MutexId ) -> bool {
196
195
let this = self . eval_context_mut ( ) ;
197
196
if let Some ( thread) = this. machine . threads . sync . mutexes [ id] . queue . pop_front ( ) {
198
197
this. unblock_thread ( thread) ;
199
- Some ( thread)
198
+ this. mutex_lock ( id, thread) ;
199
+ true
200
200
} else {
201
- None
201
+ false
202
202
}
203
203
}
204
204
@@ -266,13 +266,15 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
266
266
267
267
#[ inline]
268
268
/// Take a reader out the queue waiting for the lock.
269
- fn rwlock_dequeue_and_unblock_reader ( & mut self , id : RwLockId ) -> Option < ThreadId > {
269
+ /// Returns `true` if some thread got the rwlock.
270
+ fn rwlock_dequeue_and_lock_reader ( & mut self , id : RwLockId ) -> bool {
270
271
let this = self . eval_context_mut ( ) ;
271
272
if let Some ( reader) = this. machine . threads . sync . rwlocks [ id] . reader_queue . pop_front ( ) {
272
273
this. unblock_thread ( reader) ;
273
- Some ( reader)
274
+ this. rwlock_reader_lock ( id, reader) ;
275
+ true
274
276
} else {
275
- None
277
+ false
276
278
}
277
279
}
278
280
@@ -306,13 +308,15 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
306
308
307
309
#[ inline]
308
310
/// Take the writer out the queue waiting for the lock.
309
- fn rwlock_dequeue_and_unblock_writer ( & mut self , id : RwLockId ) -> Option < ThreadId > {
311
+ /// Returns `true` if some thread got the rwlock.
312
+ fn rwlock_dequeue_and_lock_writer ( & mut self , id : RwLockId ) -> bool {
310
313
let this = self . eval_context_mut ( ) ;
311
314
if let Some ( writer) = this. machine . threads . sync . rwlocks [ id] . writer_queue . pop_front ( ) {
312
315
this. unblock_thread ( writer) ;
313
- Some ( writer)
316
+ this. rwlock_writer_lock ( id, writer) ;
317
+ true
314
318
} else {
315
- None
319
+ false
316
320
}
317
321
}
318
322
0 commit comments