From b8b05e3b1980146ab8acb40cbe77e0271634c688 Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Sat, 15 Oct 2016 19:30:27 +0200 Subject: lib: Stabilize fast flow deallocation over local IPCP --- src/ipcpd/local/main.c | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) (limited to 'src/ipcpd') diff --git a/src/ipcpd/local/main.c b/src/ipcpd/local/main.c index 7d23c08d..b8b3335c 100644 --- a/src/ipcpd/local/main.c +++ b/src/ipcpd/local/main.c @@ -24,6 +24,7 @@ #include "ipcp.h" #include #include +#include #include #include #define OUROBOROS_PREFIX "ipcpd/local" @@ -66,8 +67,10 @@ void local_data_fini() static void * ipcp_local_sdu_loop(void * o) { while (true) { - struct rb_entry e; - int fd = local_flow_read(&e); + int fd; + struct rb_entry * e; + + fd = flow_select(NULL, NULL); pthread_rwlock_rdlock(&ipcpi.state_lock); @@ -77,13 +80,18 @@ static void * ipcp_local_sdu_loop(void * o) } pthread_rwlock_rdlock(&local_data.lock); + + e = local_flow_read(fd); + fd = local_data.in_out[fd]; - pthread_rwlock_unlock(&local_data.lock); if (fd != -1) - local_flow_write(fd, &e); + local_flow_write(fd, e); + pthread_rwlock_unlock(&local_data.lock); pthread_rwlock_unlock(&ipcpi.state_lock); + + free(e); } return (void *) 1; @@ -209,8 +217,6 @@ static int ipcp_local_flow_alloc_resp(int fd, int response) int out_fd = -1; int ret = -1; - LOG_DBG("Received response for fd %d: %d.", fd, response); - if (response) return 0; @@ -235,25 +241,22 @@ static int ipcp_local_flow_alloc_resp(int fd, int response) static int ipcp_local_flow_dealloc(int fd) { - int out_fd = -1; + struct timespec t = {0, 10000}; - pthread_rwlock_rdlock(&ipcpi.state_lock); - pthread_rwlock_wrlock(&local_data.lock); + if (fd < 0) + return -EINVAL; - out_fd = local_data.in_out[fd]; + while (flow_dealloc(fd) == -EBUSY) + nanosleep(&t, NULL); - if (out_fd != -1) { - local_data.in_out[out_fd] = -1; - flow_dealloc(out_fd); - } + pthread_rwlock_rdlock(&ipcpi.state_lock); + pthread_rwlock_wrlock(&local_data.lock); local_data.in_out[fd] = -1; pthread_rwlock_unlock(&local_data.lock); pthread_rwlock_unlock(&ipcpi.state_lock); - flow_dealloc(fd); - LOG_INFO("Flow with fd %d deallocated.", fd); return 0; -- cgit v1.2.3