rjw | 1f88458 | 2022-01-06 17:20:42 +0800 | [diff] [blame^] | 1 | #ifndef __THREAD_POOL__H_
|
| 2 | #define __THREAD_POOL__H_
|
| 3 |
|
| 4 | #include "syn_primitive.h"
|
| 5 | #include "double_list.h"
|
| 6 | #include "seq_queue.h"
|
| 7 |
|
| 8 | typedef enum {EThread_pool_unknown, EThread_pool_alloc, EThread_pool_init
|
| 9 | , EThread_pool_run, EThread_pool_exit, EThread_pool_MAX}EThread_pool_status;
|
| 10 |
|
| 11 |
|
| 12 | #define RELEASE_THREAD_INTERVAL 5*60
|
| 13 |
|
| 14 |
|
| 15 | typedef void (*THREAD_FUNC)(void *);
|
| 16 | typedef void (*USER_FUNC)(void *thread_para);
|
| 17 |
|
| 18 |
|
| 19 | typedef struct {
|
| 20 | USER_FUNC timeout_callback;
|
| 21 | unsigned long time_out;
|
| 22 | }time_out_t;
|
| 23 |
|
| 24 | typedef struct
|
| 25 | {
|
| 26 | USER_FUNC process_func;
|
| 27 | USER_FUNC release_func;
|
| 28 | void *args;
|
| 29 | time_out_t time_out_info;
|
| 30 | }thread_func_t;
|
| 31 |
|
| 32 | typedef struct
|
| 33 | {
|
| 34 | thread_func_t thread_para;
|
| 35 | unsigned int pri;
|
| 36 |
|
| 37 | BOOL busy;
|
| 38 | BOOL release;
|
| 39 |
|
| 40 | unsigned long launch_time;
|
| 41 | unsigned long time_out;
|
| 42 |
|
| 43 | EThread_pool_status *pool_status;
|
| 44 |
|
| 45 | thread_handle h_thread;
|
| 46 | condition_handle thread_cond;
|
| 47 | mutex_handle thread_lock;
|
| 48 |
|
| 49 | }thread_info_t;
|
| 50 |
|
| 51 | typedef struct
|
| 52 | {
|
| 53 | unsigned int pri;
|
| 54 | unsigned int min_thread_num;
|
| 55 | unsigned int max_thread_num;
|
| 56 |
|
| 57 | unsigned int pool_thread_num;
|
| 58 |
|
| 59 | condition_handle manage_cond;
|
| 60 | mutex_handle mange_lock;
|
| 61 |
|
| 62 | unsigned long release_threads_interval;
|
| 63 |
|
| 64 | d_list_t *idle_threads;
|
| 65 | d_list_t *busy_threads;
|
| 66 | seq_queue_t *task_queue;
|
| 67 |
|
| 68 | sem_handle sem_inc;
|
| 69 | thread_handle h_id;
|
| 70 |
|
| 71 | EThread_pool_status status;
|
| 72 | }thread_pool_t;
|
| 73 |
|
| 74 |
|
| 75 | thread_pool_t *threadpool_create(unsigned int min_thread_num, unsigned int max_thread_num);
|
| 76 | void threadpool_destroy(thread_pool_t *pool);
|
| 77 | BOOL threadpool_add(thread_pool_t *pool, USER_FUNC process_func, void *args);
|
| 78 | BOOL threadpool_add_timeout(thread_pool_t *pool, USER_FUNC process_func
|
| 79 | , USER_FUNC release_func, void *args, time_out_t *time_out);
|
| 80 | void tp_sleep(unsigned int ms);
|
| 81 |
|
| 82 | #endif //__THREAD_POOL__H_
|
| 83 |
|