2018-01-27 02:18:10 +01:00
|
|
|
#ifndef LLARP_THREADPOOL_H
|
|
|
|
#define LLARP_THREADPOOL_H
|
|
|
|
|
2018-01-29 15:27:24 +01:00
|
|
|
struct llarp_threadpool;
|
2018-01-27 02:18:10 +01:00
|
|
|
|
2018-05-22 17:54:19 +02:00
|
|
|
struct llarp_threadpool *
|
|
|
|
llarp_init_threadpool(int workers, const char *name);
|
2018-06-06 14:46:26 +02:00
|
|
|
|
|
|
|
/// for single process mode
|
|
|
|
struct llarp_threadpool *
|
|
|
|
llarp_init_same_process_threadpool();
|
|
|
|
|
2018-08-18 16:01:21 +02:00
|
|
|
typedef bool (*setup_net_func)(void *, bool);
|
2018-08-17 21:49:58 +02:00
|
|
|
typedef void (*run_main_func)(void *);
|
2018-08-08 20:02:08 +02:00
|
|
|
|
2018-08-08 19:43:46 +02:00
|
|
|
/// for network isolation
|
|
|
|
struct llarp_threadpool *
|
2018-08-09 21:02:17 +02:00
|
|
|
llarp_init_isolated_net_threadpool(const char *name, setup_net_func setupNet,
|
2018-08-17 21:49:58 +02:00
|
|
|
run_main_func runMain, void *context);
|
2018-08-08 19:43:46 +02:00
|
|
|
|
2018-05-22 17:54:19 +02:00
|
|
|
void
|
|
|
|
llarp_free_threadpool(struct llarp_threadpool **tp);
|
2018-01-27 02:18:10 +01:00
|
|
|
|
2018-02-01 14:21:00 +01:00
|
|
|
typedef void (*llarp_thread_work_func)(void *);
|
2018-01-31 20:59:26 +01:00
|
|
|
|
2018-01-29 15:27:24 +01:00
|
|
|
/** job to be done in worker thread */
|
2018-05-22 17:54:19 +02:00
|
|
|
struct llarp_thread_job
|
|
|
|
{
|
2018-01-29 15:27:24 +01:00
|
|
|
/** user data to pass to work function */
|
|
|
|
void *user;
|
|
|
|
/** called in threadpool worker thread */
|
2018-01-31 20:59:26 +01:00
|
|
|
llarp_thread_work_func work;
|
2018-07-16 06:55:46 +02:00
|
|
|
#ifdef __cplusplus
|
2018-06-06 14:46:26 +02:00
|
|
|
llarp_thread_job(void *u, llarp_thread_work_func w) : user(u), work(w)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
llarp_thread_job() : user(nullptr), work(nullptr)
|
|
|
|
{
|
|
|
|
}
|
2018-07-16 06:55:46 +02:00
|
|
|
#endif
|
2018-01-29 15:27:24 +01:00
|
|
|
};
|
2018-01-27 02:18:10 +01:00
|
|
|
|
2018-06-06 14:46:26 +02:00
|
|
|
/// for single process mode
|
|
|
|
void
|
|
|
|
llarp_threadpool_tick(struct llarp_threadpool *tp);
|
|
|
|
|
2018-05-22 17:54:19 +02:00
|
|
|
void
|
|
|
|
llarp_threadpool_queue_job(struct llarp_threadpool *tp,
|
|
|
|
struct llarp_thread_job j);
|
2018-01-29 15:27:24 +01:00
|
|
|
|
2018-05-22 17:54:19 +02:00
|
|
|
void
|
|
|
|
llarp_threadpool_stop(struct llarp_threadpool *tp);
|
|
|
|
void
|
|
|
|
llarp_threadpool_join(struct llarp_threadpool *tp);
|
2018-04-30 18:14:20 +02:00
|
|
|
|
2018-05-22 17:54:19 +02:00
|
|
|
void
|
|
|
|
llarp_threadpool_wait(struct llarp_threadpool *tp);
|
2018-01-27 02:18:10 +01:00
|
|
|
|
|
|
|
#endif
|