From 74364d19237e80081d1c6a76b46d787527638fcb Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Thu, 21 Sep 2017 16:29:01 +0200 Subject: ipcpd: Cancel threads in IPCPs This reduces CPU consumption and shutdown times. Invalidates #43 --- src/ipcpd/local/main.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src/ipcpd/local/main.c') diff --git a/src/ipcpd/local/main.c b/src/ipcpd/local/main.c index 7f44a2c6..b98e144c 100644 --- a/src/ipcpd/local/main.c +++ b/src/ipcpd/local/main.c @@ -44,8 +44,8 @@ #include #include -#define EVENT_WAIT_TIMEOUT 100 /* us */ -#define THIS_TYPE IPCP_LOCAL +#define THIS_TYPE IPCP_LOCAL +#define ALLOC_TIMEOUT 10 /* ms */ struct { struct shim_data * shim_data; @@ -95,15 +95,13 @@ static void local_data_fini(void){ static void * ipcp_local_sdu_loop(void * o) { - struct timespec timeout = {0, EVENT_WAIT_TIMEOUT * 1000}; - (void) o; - while (ipcp_get_state() == IPCP_OPERATIONAL) { + while (true) { int fd; ssize_t idx; - fevent(local_data.flows, local_data.fq, &timeout); + fevent(local_data.flows, local_data.fq, NULL); while ((fd = fqueue_next(local_data.fq)) >= 0) { idx = local_flow_read(fd); @@ -181,7 +179,7 @@ static int ipcp_local_flow_alloc(int fd, const uint8_t * dst, qoscube_t cube) { - struct timespec ts = {0, EVENT_WAIT_TIMEOUT * 1000}; + struct timespec ts = {0, ALLOC_TIMEOUT * MILLION}; struct timespec abstime; int out_fd = -1; @@ -237,7 +235,7 @@ static int ipcp_local_flow_alloc(int fd, static int ipcp_local_flow_alloc_resp(int fd, int response) { - struct timespec ts = {0, EVENT_WAIT_TIMEOUT * 1000}; + struct timespec ts = {0, ALLOC_TIMEOUT * MILLION}; struct timespec abstime; int out_fd = -1; int ret = -1; @@ -359,8 +357,10 @@ int main(int argc, ipcp_shutdown(); - if (ipcp_get_state() == IPCP_SHUTDOWN) + if (ipcp_get_state() == IPCP_SHUTDOWN) { + pthread_cancel(local_data.sduloop); pthread_join(local_data.sduloop, NULL); + } local_data_fini(); -- cgit v1.2.3