1 #ifndef THREAD_POOL_H
2 #define THREAD_POOL_H
3
4 #include <pthread.h>
5 #include <hwloc.h>
6
7
8 typedef struct _work_t{
9 int nb_args;
10 void (*task)(int nb_args, void **args, int thread_id);
11 void **args;
12 struct _work_t *next;
13 pthread_cond_t work_done;
14 pthread_mutex_t mutex;
15 int done;
16 int thread_id;
17 }work_t;
18
19 typedef struct {
20 int id;
21 hwloc_topology_t topology;
22 work_t *working_list;
23 pthread_cond_t *cond_var;
24 pthread_mutex_t *list_lock;
25 }local_thread_t;
26
27
28 typedef struct _thread_pool_t{
29 int nb_threads;
30 pthread_t *thread_list;
31 work_t *working_list;
32 pthread_cond_t *cond_var;
33 pthread_mutex_t *list_lock;
34 local_thread_t *local;
35 hwloc_topology_t topology;
36 }thread_pool_t;
37
38 int get_nb_threads(void);
39 int submit_work(work_t *work, int thread_id);
40 void wait_work_completion(work_t *work);
41 void terminate_thread_pool(void);
42 work_t *create_work(int nb_args, void **args, void (int, void **, int));
43 int test_main(void);
44 void destroy_work(work_t *work);
45
46
47
48
49 #endif