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 {
19
19
hw_pool_init_status hw_pool_init (uint32_t num_threads );
20
20
void hw_pool_destroy ();
21
21
void run_on_current_pool (qt_threadpool_func_type func , void * arg );
22
+ uint32_t get_num_delegated_threads ();
22
23
23
24
#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() {
382
382
atomic_store_explicit (& hw_pool .num_threads , 0 , memory_order_release );
383
383
}
384
384
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
+ }
388
390
389
391
// TODO: have the main thread fill the role of thread 0.
390
392
// Instead of having the main thread wait/resume, swap in its thread-locals
Original file line number Diff line number Diff line change 2
2
#include "qt_threadpool.h"
3
3
4
4
static int on_thread_test (void * arg ) {
5
+ test_check (get_num_delegated_threads () == 1 );
5
6
printf ("hello from thread\n" );
6
7
return 0 ;
7
8
}
8
9
9
10
int main () {
11
+ test_check (get_num_delegated_threads () == 1 );
10
12
hw_pool_init (2 );
13
+ test_check (get_num_delegated_threads () == 2 );
11
14
hw_pool_destroy ();
15
+ test_check (get_num_delegated_threads () == 1 );
12
16
hw_pool_init (2 );
13
17
run_on_current_pool (& on_thread_test , NULL );
14
18
hw_pool_destroy ();
You can’t perform that action at this time.
0 commit comments