Skip to content
Snippets Groups Projects
Commit 8b7eee76 authored by Avi Kivity's avatar Avi Kivity
Browse files

mutex: fix race during locking

If we failed the initial trylock, that does not mean the mutex is locked,
as it could have been unlocked right before we grabbed the wait list lock.

Retry with the wait list lock held, as the unlock path must grab it before
unlocking.
parent 26f7cd19
No related branches found
No related tags found
No related merge requests found
......@@ -17,6 +17,11 @@ extern "C" void mutex_lock(mutex_t *mutex)
w.thread = sched::thread::current();
spin_lock(&mutex->_wait_lock);
if (mutex_trylock(mutex)) {
// mutex was unlocked just before we grabbed _wait_lock
spin_unlock(&mutex->_wait_lock);
return;
}
if (!mutex->_wait_list.first) {
mutex->_wait_list.first = &w;
} else {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment