Nilorea Library

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

All Data Structures Files Functions Variables Typedefs Macros Groups
n_thread_pool.h
Go to the documentation of this file.
1
7 #ifndef NILOREA_THREAD_POOL_LIBRARY
8 #define NILOREA_THREAD_POOL_LIBRARY
9
10 #ifdef __cplusplus
11 extern "C"
12 {
13 #endif
14
20 #include "n_log.h"
21 #include "n_common.h"
22 #include <pthread.h>
23 #include <semaphore.h>
24
25
27 #define SYNCED_PROC 1
28
29 #define DIRECT_PROC 2
30
31 #define IDLE_THREAD 1
32
33 #define BUSY_THREAD 2
34
35 #define RUNNING_THREAD 3
36
37 #define EXITING_THREAD 4
38
40 typedef struct THREAD_POOL_NODE
41 {
43 void *(*func)(void *param);
45 void *param ;
47 sem_t th_start ,
49 th_end ;
51 pthread_mutex_t lock ;
53 int type ;
55 int state ;
57 pthread_t thr ;
58
59 } THREAD_POOL_NODE ;
60
61
63 typedef struct THREAD_POOL
64 {
66 THREAD_POOL_NODE **thread_list ;
68 int max_threads ;
69 } THREAD_POOL ;
70
71 /* allocate a new thread pool */
72 THREAD_POOL *new_thread_pool( int nbmaxthr );
73 /* add a function to run in an available thread inside a pool */
74 int add_threaded_process( THREAD_POOL *thread_pool , void *(*func_ptr)(void *param) , void *param , int mode );
75 /* tell all the waiting threads to start their associated process */
76 int start_threaded_pool( THREAD_POOL *thread_pool );
77 /* wait for all busy thread to finish */
78 int wait_for_threaded_pool( THREAD_POOL *thread_pool );
79
82 #ifdef __cplusplus
83 }
84 #endif
85
86 #endif
87