27 */ |
27 */ |
28 |
28 |
29 #ifndef THREADPOOL_H |
29 #ifndef THREADPOOL_H |
30 #define THREADPOOL_H |
30 #define THREADPOOL_H |
31 |
31 |
|
32 #include "../public/nsapi.h" |
32 #include <pthread.h> |
33 #include <pthread.h> |
33 |
34 |
34 #ifdef __cplusplus |
35 #ifdef __cplusplus |
35 extern "C" { |
36 extern "C" { |
36 #endif |
37 #endif |
37 |
38 |
38 typedef struct _pool_queue pool_queue_t; |
39 typedef struct _pool_queue pool_queue_t; |
39 typedef struct _thread_pool { |
40 struct _thread_pool { |
40 pthread_mutex_t queue_lock; |
41 pthread_mutex_t queue_lock; |
41 pthread_mutex_t avlbl_lock; |
42 pthread_mutex_t avlbl_lock; |
42 pthread_cond_t available; |
43 pthread_cond_t available; |
|
44 pool_queue_t *queue; |
43 int queue_len; |
45 int queue_len; |
44 pool_queue_t *queue; |
46 }; |
45 } threadpool_t; |
|
46 |
47 |
47 typedef void*(*job_callback_f)(void *data); |
48 struct _threadpool_job { |
48 typedef struct _threadpool_job { |
|
49 job_callback_f callback; |
49 job_callback_f callback; |
50 void *data; |
50 void *data; |
51 } threadpool_job; |
51 }; |
52 |
52 |
53 struct _pool_queue { |
53 struct _pool_queue { |
54 threadpool_job *job; |
54 threadpool_job *job; |
55 pool_queue_t *next; |
55 pool_queue_t *next; |
56 }; |
56 }; |
57 |
57 |
58 |
|
59 threadpool_t* threadpool_new(int n); |
|
60 |
|
61 void* threadpool_func(void *data); |
|
62 |
|
63 threadpool_job* threadpool_get_job(threadpool_t *pool); |
|
64 |
|
65 void threadpool_run(threadpool_t *pool, job_callback_f func, void *data); |
|
66 |
|
67 #ifdef __cplusplus |
58 #ifdef __cplusplus |
68 } |
59 } |
69 #endif |
60 #endif |
70 |
61 |
71 #endif /* THREADPOOL_H */ |
62 #endif /* THREADPOOL_H */ |