File tree Expand file tree Collapse file tree 3 files changed +10
-3
lines changed Expand file tree Collapse file tree 3 files changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -19,5 +19,6 @@ typedef enum {
1919hw_pool_init_status hw_pool_init (uint32_t num_threads );
2020void hw_pool_destroy ();
2121void run_on_current_pool (qt_threadpool_func_type func , void * arg );
22+ uint32_t get_num_delegated_threads ();
2223
2324#endif
Original file line number Diff line number Diff line change @@ -382,9 +382,11 @@ 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: interface for querying about the owned thread pool.
386- // At least let the user get the number of threads available.
387- // If no thread pool is owned, just report a single thread.
385+ API_FUNC uint32_t get_num_delegated_threads () {
386+ if (owned_pool ) return owned_pool -> num_threads ;
387+ // Every thread at least has itself available for work.
388+ return 1 ;
389+ }
388390
389391// TODO: have the main thread fill the role of thread 0.
390392// Instead of having the main thread wait/resume, swap in its thread-locals
Original file line number Diff line number Diff line change 22#include "qt_threadpool.h"
33
44static int on_thread_test (void * arg ) {
5+ test_check (get_num_delegated_threads () == 1 );
56 printf ("hello from thread\n" );
67 return 0 ;
78}
89
910int main () {
11+ test_check (get_num_delegated_threads () == 1 );
1012 hw_pool_init (2 );
13+ test_check (get_num_delegated_threads () == 2 );
1114 hw_pool_destroy ();
15+ test_check (get_num_delegated_threads () == 1 );
1216 hw_pool_init (2 );
1317 run_on_current_pool (& on_thread_test , NULL );
1418 hw_pool_destroy ();
You can’t perform that action at this time.
0 commit comments