Skip to content

Commit bdf2e8d

Browse files
Have threads with no owned pool execute run_on_all calls themselves.
1 parent 2429e16 commit bdf2e8d

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/threadpool.c

+8-3
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,6 @@ API_FUNC __attribute__((no_sanitize("memory"))) void hw_pool_destroy() {
382382
atomic_store_explicit(&hw_pool.num_threads, 0, memory_order_release);
383383
}
384384

385-
// TODO: If no thread pool is owned, have a thread run the function directly.
386-
387385
// TODO: interface for querying about the owned thread pool.
388386
// At least let the user get the number of threads available.
389387
// If no thread pool is owned, just report a single thread.
@@ -416,7 +414,14 @@ pool_run_on_all(pool_header *pool, qt_threadpool_func_type func, void *arg) {
416414
}
417415

418416
API_FUNC void run_on_current_pool(qt_threadpool_func_type func, void *arg) {
419-
pool_run_on_all(owned_pool, func, arg);
417+
if (owned_pool) {
418+
pool_run_on_all(owned_pool, func, arg);
419+
} else {
420+
uint32_t outer_index = context_index;
421+
context_index = 0;
422+
func(arg);
423+
context_index = outer_index;
424+
}
420425
}
421426

422427
API_FUNC void hw_pool_run_on_all(qt_threadpool_func_type func, void *arg) {

0 commit comments

Comments
 (0)