mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2025-01-01 12:46:12 +00:00
c/multi: Fix condition var waiting for wait thread.
Spurious wakeups happen, have to actually have a condition to check in a loop with the cond var wait.
This commit is contained in:
parent
d523001b6e
commit
fd3a0a1435
|
@ -226,6 +226,7 @@ run_func(void *ptr)
|
|||
while (os_thread_helper_is_running_locked(&mc->wait_thread.oth)) {
|
||||
|
||||
if (mc->wait_thread.xcsem == NULL && mc->wait_thread.xcf == NULL) {
|
||||
//! @todo what condition should we spin on here to handle spurious wakeups?
|
||||
os_thread_helper_wait_locked(&mc->wait_thread.oth);
|
||||
// Fall through here on stopping to clean up and outstanding waits.
|
||||
}
|
||||
|
@ -274,6 +275,8 @@ run_func(void *ptr)
|
|||
mc->wait_thread.waiting = false;
|
||||
|
||||
if (mc->wait_thread.blocked) {
|
||||
// Release one thread
|
||||
mc->wait_thread.blocked = false;
|
||||
os_thread_helper_signal_locked(&mc->wait_thread.oth);
|
||||
}
|
||||
}
|
||||
|
@ -289,9 +292,12 @@ wait_for_wait_thread_locked(struct multi_compositor *mc)
|
|||
// Should we wait for the last frame.
|
||||
if (mc->wait_thread.waiting) {
|
||||
COMP_TRACE_IDENT(blocked);
|
||||
|
||||
// OK, wait until the wait thread releases us by setting blocked to false
|
||||
mc->wait_thread.blocked = true;
|
||||
os_thread_helper_wait_locked(&mc->wait_thread.oth);
|
||||
mc->wait_thread.blocked = false;
|
||||
while (mc->wait_thread.blocked) {
|
||||
os_thread_helper_wait_locked(&mc->wait_thread.oth);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -146,7 +146,12 @@ struct multi_compositor
|
|||
//! Is the thread waiting, if so the client should block.
|
||||
bool waiting;
|
||||
|
||||
//! Is the client thread blocked, if so it should be woken up.
|
||||
/*!
|
||||
* Is the client thread blocked?
|
||||
*
|
||||
* Set to true by the client thread,
|
||||
* cleared by the wait thread to release the client thread.
|
||||
*/
|
||||
bool blocked;
|
||||
} wait_thread;
|
||||
|
||||
|
|
Loading…
Reference in a new issue