Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 10d978c

Browse files
committed
Inline _create() calls and add assertions
1 parent a5db2c3 commit 10d978c

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/sync.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,13 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
223223
F: FnOnce(&mut MiriEvalContext<'mir, 'tcx>, MutexId) -> InterpResult<'tcx, Option<MutexId>>,
224224
{
225225
let this = self.eval_context_mut();
226-
if let Some(old) = existing(this, this.machine.threads.sync.mutexes.next_index())? {
226+
let next_index = this.machine.threads.sync.mutexes.next_index();
227+
if let Some(old) = existing(this, next_index)? {
227228
Ok(old)
228229
} else {
229-
Ok(self.mutex_create())
230+
let new_index = this.machine.threads.sync.mutexes.push(Default::default());
231+
assert_eq!(next_index, new_index);
232+
Ok(new_index)
230233
}
231234
}
232235

@@ -323,10 +326,13 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
323326
) -> InterpResult<'tcx, Option<RwLockId>>,
324327
{
325328
let this = self.eval_context_mut();
326-
if let Some(old) = existing(this, this.machine.threads.sync.rwlocks.next_index())? {
329+
let next_index = this.machine.threads.sync.rwlocks.next_index();
330+
if let Some(old) = existing(this, next_index)? {
327331
Ok(old)
328332
} else {
329-
Ok(self.rwlock_create())
333+
let new_index = this.machine.threads.sync.rwlocks.push(Default::default());
334+
assert_eq!(next_index, new_index);
335+
Ok(new_index)
330336
}
331337
}
332338

@@ -489,10 +495,13 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
489495
) -> InterpResult<'tcx, Option<CondvarId>>,
490496
{
491497
let this = self.eval_context_mut();
492-
if let Some(old) = existing(this, this.machine.threads.sync.condvars.next_index())? {
498+
let next_index = this.machine.threads.sync.condvars.next_index();
499+
if let Some(old) = existing(this, next_index)? {
493500
Ok(old)
494501
} else {
495-
Ok(self.condvar_create())
502+
let new_index = this.machine.threads.sync.condvars.push(Default::default());
503+
assert_eq!(next_index, new_index);
504+
Ok(new_index)
496505
}
497506
}
498507

0 commit comments

Comments
 (0)