]> git.lizzy.rs Git - rust.git/blobdiff - src/sync.rs
Auto merge of #2426 - saethlin:unix-exec, r=RalfJung
[rust.git] / src / sync.rs
index fb69c67eccd9f095c625ac8b0fc180a467afb9da..5571bbd8f2dc577da6257c1e069a617212170edb 100644 (file)
@@ -42,7 +42,7 @@ fn index(self) -> usize {
         }
 
         impl $name {
-            pub fn to_u32_scalar<'tcx>(&self) -> Scalar<Tag> {
+            pub fn to_u32_scalar<'tcx>(&self) -> Scalar<Provenance> {
                 Scalar::from_u32(self.0.get())
             }
         }
@@ -223,10 +223,13 @@ fn mutex_get_or_create<F>(&mut self, existing: F) -> InterpResult<'tcx, MutexId>
         F: FnOnce(&mut MiriEvalContext<'mir, 'tcx>, MutexId) -> InterpResult<'tcx, Option<MutexId>>,
     {
         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<F>(&mut self, existing: F) -> InterpResult<'tcx, RwLockI
         ) -> InterpResult<'tcx, Option<RwLockId>>,
     {
         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<F>(&mut self, existing: F) -> InterpResult<'tcx, Condva
         ) -> InterpResult<'tcx, Option<CondvarId>>,
     {
         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)
         }
     }