From b41addbbe742d2c8bbecf474fcea3f47ce040bd0 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Thu, 26 May 2022 20:50:29 +0100 Subject: [PATCH] t/hand: Document and fix cond var loop --- src/xrt/tracking/hand/t_hand_tracking_async.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/xrt/tracking/hand/t_hand_tracking_async.c b/src/xrt/tracking/hand/t_hand_tracking_async.c index 59b133f3b..0295dc820 100644 --- a/src/xrt/tracking/hand/t_hand_tracking_async.c +++ b/src/xrt/tracking/hand/t_hand_tracking_async.c @@ -61,16 +61,18 @@ ht_async_mainloop(void *ptr) os_thread_helper_lock(&hta->mainloop); - while (hta->mainloop.running) { + while (os_thread_helper_is_running_locked(&hta->mainloop)) { // No new frame, wait. if (hta->frames[0] == NULL && hta->frames[1] == NULL) { os_thread_helper_wait_locked(&hta->mainloop); - } - // In this case, we were woken up because Monado is exiting and we need to exit too - if (!hta->mainloop.running) { - break; + /* + * Loop back to the top to check if we should stop, + * also handles spurious wakeups by re-checking the + * condition in the if case. Essentially two loops. + */ + continue; } os_thread_helper_unlock(&hta->mainloop);