From 10d978c180217f09c576822a312bc7353adfc17c Mon Sep 17 00:00:00 2001 From: Andy Wang Date: Thu, 12 May 2022 21:06:17 +0100 Subject: [PATCH] Inline _create() calls and add assertions --- src/sync.rs | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/sync.rs b/src/sync.rs index fb69c67eccd..0eebe4f654e 100644 --- a/src/sync.rs +++ b/src/sync.rs @@ -223,10 +223,13 @@ fn mutex_get_or_create(&mut self, existing: F) -> InterpResult<'tcx, MutexId> F: FnOnce(&mut MiriEvalContext<'mir, 'tcx>, MutexId) -> InterpResult<'tcx, Option>, { let this = self.eval_context_mut(); - if let Some(old) = existing(this, this.machine.threads.sync.mutexes.next_index())? { + let next_index = this.machine.threads.sync.mutexes.next_index(); + if let Some(old) = existing(this, next_index)? { Ok(old) } else { - Ok(self.mutex_create()) + let new_index = this.machine.threads.sync.mutexes.push(Default::default()); + assert_eq!(next_index, new_index); + Ok(new_index) } } @@ -323,10 +326,13 @@ fn rwlock_get_or_create(&mut self, existing: F) -> InterpResult<'tcx, RwLockI ) -> InterpResult<'tcx, Option>, { let this = self.eval_context_mut(); - if let Some(old) = existing(this, this.machine.threads.sync.rwlocks.next_index())? { + let next_index = this.machine.threads.sync.rwlocks.next_index(); + if let Some(old) = existing(this, next_index)? { Ok(old) } else { - Ok(self.rwlock_create()) + let new_index = this.machine.threads.sync.rwlocks.push(Default::default()); + assert_eq!(next_index, new_index); + Ok(new_index) } } @@ -489,10 +495,13 @@ fn condvar_get_or_create(&mut self, existing: F) -> InterpResult<'tcx, Condva ) -> InterpResult<'tcx, Option>, { let this = self.eval_context_mut(); - if let Some(old) = existing(this, this.machine.threads.sync.condvars.next_index())? { + let next_index = this.machine.threads.sync.condvars.next_index(); + if let Some(old) = existing(this, next_index)? { Ok(old) } else { - Ok(self.condvar_create()) + let new_index = this.machine.threads.sync.condvars.push(Default::default()); + assert_eq!(next_index, new_index); + Ok(new_index) } }