The open source OpenXR runtime
0
fork

Configure Feed

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

u/worker: Split tracking of waiting tasks and in progress tasks

Without this the code could deadlock on wait_all because the count
would get out of sync when pushing more tasks then threads without
waiting on the work.

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

authored by

Jakob Bornecrantz and committed by
Marge Bot
325bcbe6 acd3d464

+25 -7
+25 -7
src/xrt/auxiliary/util/u_worker.c
··· 95 95 //! Pointer to poll of threads. 96 96 struct u_worker_thread_pool *uwtp; 97 97 98 - //! Number of tasks that is pending or being worked on in this group. 99 - size_t current_submitted_tasks_count; 98 + /*! 99 + * The number of tasks that are pending execution by a worker. 100 + * They reside in the pool::tasks array. 101 + */ 102 + uint32_t current_tasks_in_array; 103 + 104 + /*! 105 + * Number of tasks that are being worked on. 106 + * They live inside of the working thread. 107 + */ 108 + uint32_t current_working_tasks; 100 109 101 110 /*! 102 111 * Number of waiting threads that have been released by a worker, ··· 147 156 continue; 148 157 } 149 158 150 - *out_task = p->tasks[i]; 159 + struct task task = p->tasks[i]; 151 160 p->tasks[i] = (struct task){NULL, NULL, NULL}; 161 + 152 162 p->tasks_in_array_count--; 163 + task.g->current_tasks_in_array--; 164 + task.g->current_working_tasks++; 165 + 166 + *out_task = task; 167 + 153 168 return; 154 169 } 155 170 ··· 168 183 169 184 p->tasks[i] = (struct task){g, func, data}; 170 185 p->tasks_in_array_count++; 171 - g->current_submitted_tasks_count++; 186 + g->current_tasks_in_array++; 172 187 return; 173 188 } 174 189 ··· 207 222 static bool 208 223 locked_group_has_tasks_waiting_or_inflight(const struct group *g) 209 224 { 210 - if (g->current_submitted_tasks_count == 0) { 225 + if (g->current_tasks_in_array == 0 && g->current_working_tasks == 0) { 211 226 return false; 212 227 } 213 228 ··· 375 390 // No longer working. 376 391 p->working_count--; 377 392 378 - // Only now decrement the task count on the owning group. 379 - task.g->current_submitted_tasks_count--; 393 + // We are no longer working on the task. 394 + task.g->current_working_tasks--; 395 + 396 + // This must hold true. 397 + assert(task.g->current_tasks_in_array <= p->tasks_in_array_count); 380 398 381 399 // Wake up any waiter. 382 400 locked_group_wake_waiter_if_allowed(p, task.g);