From 0b6ec575b9d0c683b854ba4ea3da726620c209b9 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 30 May 2020 22:54:37 +0200 Subject: [PATCH] make mutex_unlock infallible --- src/shims/sync.rs | 4 ++-- src/sync.rs | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/shims/sync.rs b/src/shims/sync.rs index 39a087dc9ac..8986455a14f 100644 --- a/src/shims/sync.rs +++ b/src/shims/sync.rs @@ -316,7 +316,7 @@ fn release_cond_mutex_and_block<'mir, 'tcx: 'mir>( active_thread: ThreadId, mutex: MutexId, ) -> InterpResult<'tcx> { - if let Some(old_locked_count) = ecx.mutex_unlock(mutex, active_thread)? { + if let Some(old_locked_count) = ecx.mutex_unlock(mutex, active_thread) { if old_locked_count != 1 { throw_unsup_format!("awaiting on a lock acquired multiple times is not supported"); } @@ -486,7 +486,7 @@ fn pthread_mutex_unlock(&mut self, mutex_op: OpTy<'tcx, Tag>) -> InterpResult<'t let id = mutex_get_or_create_id(this, mutex_op)?; let active_thread = this.get_active_thread(); - if let Some(_old_locked_count) = this.mutex_unlock(id, active_thread)? { + if let Some(_old_locked_count) = this.mutex_unlock(id, active_thread) { // The mutex was locked by the current thread. Ok(0) } else { diff --git a/src/sync.rs b/src/sync.rs index 5ba29b5afa2..0d4b4d6b7c1 100644 --- a/src/sync.rs +++ b/src/sync.rs @@ -153,14 +153,14 @@ fn mutex_unlock( &mut self, id: MutexId, expected_owner: ThreadId, - ) -> InterpResult<'tcx, Option> { + ) -> Option { let this = self.eval_context_mut(); let mutex = &mut this.machine.threads.sync.mutexes[id]; if let Some(current_owner) = mutex.owner { // Mutex is locked. if current_owner != expected_owner { // Only the owner can unlock the mutex. - return Ok(None); + return None; } let old_lock_count = mutex.lock_count; mutex.lock_count = old_lock_count @@ -172,10 +172,10 @@ fn mutex_unlock( // to another thread. this.mutex_dequeue_and_lock(id); } - Ok(Some(old_lock_count)) + Some(old_lock_count) } else { // Mutex is unlocked. - Ok(None) + None } } -- 2.44.0