123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- #ifndef THREADPOOL_H
- #define THREADPOOL_H
- #pragma once
- #include "config.h"
- #include "memutil.h"
- #ifdef __cplusplus
- extern "C" {
- #endif
- typedef struct threadpool_t threadpool_t;
- typedef struct strand_t strand_t;
- typedef void (*threadpool_workitem_proc)(threadpool_t *threadpool, void *arg);
- typedef void (*threadpool_workitem_proc2)(threadpool_t *threadpool, void *arg, param_size_t param1, param_size_t param2);
- typedef void (*threadpool_decorator_callback)(threadpool_t *threadpool, void *user_data);
- TOOLKIT_API int threadpool_create(threadpool_t **p_threadpool);
- TOOLKIT_API int threadpool_destroy(threadpool_t *threadpool);
- TOOLKIT_API int threadpool_set_thread_decorator(threadpool_t *threadpool,
- threadpool_decorator_callback dc_init,
- threadpool_decorator_callback dc_term,
- void *user_data);
- TOOLKIT_API int threadpool_start(threadpool_t *threadpool,
- int num_fix_thread,
- int max_tmp_thread,
- int tmp_thread_ttl,
- int stack_size); // zero for default
- TOOLKIT_API int threadpool_stop(threadpool_t *threadpool);
- TOOLKIT_API int threadpool_queue_workitem(threadpool_t *threadpool,
- strand_t *strand,
- threadpool_workitem_proc workitem,
- void *arg);
- TOOLKIT_API int threadpool_queue_workitem2(threadpool_t *threadpool,
- strand_t *strand,
- threadpool_workitem_proc2 workitem,
- void *arg,
- param_size_t param1,
- param_size_t param2);
- #define threadpool_post_workitem_fifo threadpool_queue_workitem
- #define threadpool_post_workitem_fifo2 threadpool_queue_workitem2
- TOOLKIT_API int threadpool_post_workitem_lifo(threadpool_t *threadpool,
- strand_t *strand,
- threadpool_workitem_proc workitem,
- void *arg);
- TOOLKIT_API int threadpool_post_workitem_lifo2(threadpool_t *threadpool,
- strand_t *strand,
- threadpool_workitem_proc2 workitem,
- void *arg,
- param_size_t param1,
- param_size_t param2);
- TOOLKIT_API void threadpool_set_user_data(threadpool_t *threadpool, void *user_data);
- TOOLKIT_API void *threadpool_get_user_data(threadpool_t *threadpool);
- typedef void (*log_func)(threadpool_t *threadpool, const char*);
- TOOLKIT_API void threadpool_set_log(threadpool_t *threadpool, log_func func);
- TOOLKIT_API strand_t *strand_create();
- TOOLKIT_API int strand_dec_ref(strand_t *strand);
- TOOLKIT_API int strand_inc_ref(strand_t *strand);
- TOOLKIT_API int strand_ref_cnt(strand_t *strand);
- TOOLKIT_API void strand_lock(strand_t *strand);
- TOOLKIT_API void strand_unlock(strand_t *strand);
- static void strand_destroy(strand_t *strand) { strand_dec_ref(strand); }
- #ifdef __cplusplus
- } // extern "C" {
- #endif
- #endif // THREADPOOL_H
|