@@ -75,6 +75,8 @@ typedef struct {
7575#endif
7676} pool_header ;
7777
78+ _Thread_local pool_header * owned_pool ;
79+
7880typedef struct {
7981 // 16 byte aligned to allow loading it in one atomic instruction
8082 // on architectures where that makes sense (most of them).
@@ -306,6 +308,7 @@ API_FUNC hw_pool_init_status hw_pool_init(uint32_t num_threads) {
306308#ifdef QPOOL_USE_PTHREADS
307309 pthread_attr_destroy (& attr );
308310#endif
311+ owned_pool = & hw_pool ;
309312 return POOL_INIT_SUCCESS ;
310313cleanup_threads :
311314 if (i ) {
@@ -348,6 +351,7 @@ API_FUNC hw_pool_init_status hw_pool_init(uint32_t num_threads) {
348351}
349352
350353API_FUNC __attribute__((no_sanitize ("memory" ))) void hw_pool_destroy () {
354+ owned_pool = NULL ;
351355 uint32_t num_threads =
352356 atomic_load_explicit (& hw_pool .num_threads , memory_order_relaxed );
353357 char * buffer = atomic_load_explicit (& hw_pool .threads , memory_order_relaxed );
@@ -400,6 +404,10 @@ pool_run_on_all(pool_header *pool, qt_threadpool_func_type func, void *arg) {
400404 suspend_main_while_working (pool );
401405}
402406
407+ API_FUNC void run_on_current_pool (qt_threadpool_func_type func , void * arg ) {
408+ pool_run_on_all (owned_pool , func , arg );
409+ }
410+
403411API_FUNC void hw_pool_run_on_all (qt_threadpool_func_type func , void * arg ) {
404412 pool_run_on_all (& hw_pool , func , arg );
405413}
0 commit comments