Skip to content

Commit

Permalink
make mutex_unlock infallible
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed May 30, 2020
1 parent 67ad304 commit 0b6ec57
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/shims/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down Expand Up @@ -486,7 +486,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
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 {
Expand Down
8 changes: 4 additions & 4 deletions src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,14 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
&mut self,
id: MutexId,
expected_owner: ThreadId,
) -> InterpResult<'tcx, Option<usize>> {
) -> Option<usize> {
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
Expand All @@ -172,10 +172,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
// 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
}
}

Expand Down

0 comments on commit 0b6ec57

Please sign in to comment.