The open source OpenXR runtime
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

u/worker: Small improvements

Part-of: <https://gitlab.freedesktop.org/monado/monado/-/merge_requests/2619>

authored by

Jakob Bornecrantz and committed by
Marge Bot
acd3d464 5266d0ac

+23 -8
+23 -8
src/xrt/auxiliary/util/u_worker.c
··· 98 98 //! Number of tasks that is pending or being worked on in this group. 99 99 size_t current_submitted_tasks_count; 100 100 101 - //! Number of threads that have been released or newly entered wait. 101 + /*! 102 + * Number of waiting threads that have been released by a worker, 103 + * or a thread that has started waiting (see u_worker_group_wait_all). 104 + */ 102 105 size_t released_count; 103 106 104 107 struct ··· 202 205 */ 203 206 204 207 static bool 205 - locked_group_should_enter_wait_loop(struct pool *p, struct group *g) 208 + locked_group_has_tasks_waiting_or_inflight(const struct group *g) 206 209 { 207 210 if (g->current_submitted_tasks_count == 0) { 208 211 return false; 209 212 } 210 - 211 - // Enter the loop as a released thread. 212 - g->released_count++; 213 213 214 214 return true; 215 215 } ··· 238 238 */ 239 239 240 240 // Tasks available. 241 - if (g->current_submitted_tasks_count > 0) { 241 + if (locked_group_has_tasks_waiting_or_inflight(g)) { 242 242 243 243 // We have been released or newly entered the loop. 244 244 if (g->released_count > 0) { ··· 266 266 locked_group_wake_waiter_if_allowed(struct pool *p, struct group *g) 267 267 { 268 268 // Are there still outstanding tasks? 269 - if (g->current_submitted_tasks_count > 0) { 269 + if (locked_group_has_tasks_waiting_or_inflight(g)) { 270 270 return; 271 271 } 272 272 ··· 534 534 os_mutex_lock(&p->mutex); 535 535 536 536 // Can we early out? 537 - if (!locked_group_should_enter_wait_loop(p, g)) { 537 + if (!locked_group_has_tasks_waiting_or_inflight(g)) { 538 538 os_mutex_unlock(&p->mutex); 539 539 return; 540 540 } 541 + 542 + /* 543 + * The released_count is tied to the decrement of worker_limit, that is 544 + * when a waiting thread is woken up the worker_limit is decreased, and 545 + * released_count is increased. The waiting thread will then double 546 + * check that it can be released or not, if it can not be released it 547 + * will once again donate this thread and increase the worker_limit. 548 + * 549 + * If it can be released it will decrement released_count and exit the 550 + * loop below. 551 + * 552 + * So if we increment it here, the loop will increase worker_limit 553 + * which is what we want. 554 + */ 555 + g->released_count++; 541 556 542 557 // Wait here until all work been started and completed. 543 558 while (locked_group_should_wait(p, g)) {