mirror of https://github.com/oxen-io/lokinet
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
1.4 KiB
C
63 lines
1.4 KiB
C
7 years ago
|
#ifndef LLARP_THREADPOOL_H
|
||
|
#define LLARP_THREADPOOL_H
|
||
|
|
||
7 years ago
|
struct llarp_threadpool;
|
||
7 years ago
|
|
||
6 years ago
|
struct llarp_threadpool *
|
||
|
llarp_init_threadpool(int workers, const char *name);
|
||
6 years ago
|
|
||
|
/// for single process mode
|
||
|
struct llarp_threadpool *
|
||
|
llarp_init_same_process_threadpool();
|
||
|
|
||
6 years ago
|
typedef bool (*setup_net_func)(void *, bool);
|
||
6 years ago
|
typedef void (*run_main_func)(void *);
|
||
6 years ago
|
|
||
6 years ago
|
/// for network isolation
|
||
|
struct llarp_threadpool *
|
||
6 years ago
|
llarp_init_isolated_net_threadpool(const char *name, setup_net_func setupNet,
|
||
6 years ago
|
run_main_func runMain, void *context);
|
||
6 years ago
|
|
||
6 years ago
|
void
|
||
|
llarp_free_threadpool(struct llarp_threadpool **tp);
|
||
7 years ago
|
|
||
7 years ago
|
typedef void (*llarp_thread_work_func)(void *);
|
||
7 years ago
|
|
||
7 years ago
|
/** job to be done in worker thread */
|
||
6 years ago
|
struct llarp_thread_job
|
||
|
{
|
||
7 years ago
|
/** user data to pass to work function */
|
||
|
void *user;
|
||
|
/** called in threadpool worker thread */
|
||
7 years ago
|
llarp_thread_work_func work;
|
||
6 years ago
|
#ifdef __cplusplus
|
||
6 years ago
|
llarp_thread_job(void *u, llarp_thread_work_func w) : user(u), work(w)
|
||
|
{
|
||
|
}
|
||
|
|
||
|
llarp_thread_job() : user(nullptr), work(nullptr)
|
||
|
{
|
||
|
}
|
||
6 years ago
|
#endif
|
||
7 years ago
|
};
|
||
7 years ago
|
|
||
6 years ago
|
/// for single process mode
|
||
|
void
|
||
|
llarp_threadpool_tick(struct llarp_threadpool *tp);
|
||
|
|
||
6 years ago
|
void
|
||
|
llarp_threadpool_queue_job(struct llarp_threadpool *tp,
|
||
|
struct llarp_thread_job j);
|
||
6 years ago
|
void
|
||
|
llarp_threadpool_start(struct llarp_threadpool *tp);
|
||
7 years ago
|
|
||
6 years ago
|
void
|
||
|
llarp_threadpool_stop(struct llarp_threadpool *tp);
|
||
|
void
|
||
|
llarp_threadpool_join(struct llarp_threadpool *tp);
|
||
7 years ago
|
|
||
6 years ago
|
void
|
||
|
llarp_threadpool_wait(struct llarp_threadpool *tp);
|
||
7 years ago
|
|
||
|
#endif
|