feat: change lnm loop multithreading api
This commit is contained in:
parent
ccb9b77cc8
commit
9c01548256
5 changed files with 52 additions and 36 deletions
|
|
@ -81,7 +81,8 @@ lnm_err lnm_http_route_init_regex(lnm_http_route **out, lnm_http_method method,
|
|||
*/
|
||||
lnm_err lnm_http_loop_route_add(lnm_http_loop *hl, lnm_http_route *route);
|
||||
|
||||
lnm_err lnm_http_loop_run(lnm_http_loop *hl, uint16_t port, int thread_count);
|
||||
lnm_err lnm_http_loop_run(lnm_http_loop *hl, uint16_t port,
|
||||
size_t epoll_threads, size_t worker_threads);
|
||||
|
||||
void lnm_http_loop_set_api_key(lnm_http_loop *hl, const char *api_key);
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
#include "lnm/common.h"
|
||||
|
||||
#define LNM_LOOP_BUF_SIZE 2048
|
||||
#define LNM_QUEUE_MULTIPLIER 8
|
||||
|
||||
typedef enum lnm_loop_state {
|
||||
lnm_loop_state_req = 0,
|
||||
|
|
@ -77,6 +78,12 @@ typedef struct lnm_loop {
|
|||
void (*data_read)(lnm_loop_conn *conn);
|
||||
void (*data_write)(lnm_loop_conn *conn);
|
||||
lnm_loop_queue *wq;
|
||||
struct {
|
||||
// Mutex shared between all threads; used for counting thread IDs
|
||||
pthread_mutex_t mutex;
|
||||
size_t worker_count;
|
||||
size_t epoll_count;
|
||||
} threads;
|
||||
} lnm_loop;
|
||||
|
||||
lnm_err lnm_loop_init(lnm_loop **out, void *gctx,
|
||||
|
|
@ -87,7 +94,16 @@ lnm_err lnm_loop_init(lnm_loop **out, void *gctx,
|
|||
|
||||
lnm_err lnm_loop_setup(lnm_loop *l, uint16_t port);
|
||||
|
||||
lnm_err lnm_loop_run(lnm_loop *l, int thread_count);
|
||||
/**
|
||||
* Run a single epoll thread of the event loop.
|
||||
*/
|
||||
lnm_err lnm_loop_run(lnm_loop *l);
|
||||
|
||||
/**
|
||||
* Run a multithreaded event loop with the configured number of threads.
|
||||
*/
|
||||
lnm_err lnm_loop_run_multi(lnm_loop *l, size_t epoll_threads,
|
||||
size_t worker_threads);
|
||||
|
||||
/**
|
||||
* Reschedule the given connection, either on the event loop for network IO or
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue