diff options
author | Sander Vrijders <sander.vrijders@intec.ugent.be> | 2016-10-17 09:08:21 +0000 |
---|---|---|
committer | Sander Vrijders <sander.vrijders@intec.ugent.be> | 2016-10-17 09:08:21 +0000 |
commit | afb04d957a5322d483e6422f3baf1a651915af10 (patch) | |
tree | 038cbefec387fc15af2dd0b8325b063977a08590 /src/ipcpd/local | |
parent | 059dc0f942330b1e8a989f37a7caf3766f8e6c50 (diff) | |
parent | c79ab46894053312f80390bf13a52c238a7d4704 (diff) | |
download | ouroboros-afb04d957a5322d483e6422f3baf1a651915af10.tar.gz ouroboros-afb04d957a5322d483e6422f3baf1a651915af10.zip |
Merged in dstaesse/ouroboros/be-fp (pull request #265)
lib: Stabilize fast flow deallocation over local IPCP
Diffstat (limited to 'src/ipcpd/local')
-rw-r--r-- | src/ipcpd/local/main.c | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/src/ipcpd/local/main.c b/src/ipcpd/local/main.c index 7d23c08d..4e500a8a 100644 --- a/src/ipcpd/local/main.c +++ b/src/ipcpd/local/main.c @@ -24,6 +24,8 @@ #include "ipcp.h" #include <ouroboros/errno.h> #include <ouroboros/dev.h> +#include <ouroboros/fcntl.h> +#include <ouroboros/select.h> #include <ouroboros/ipcp-dev.h> #include <ouroboros/local-dev.h> #define OUROBOROS_PREFIX "ipcpd/local" @@ -66,8 +68,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 +81,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 +218,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 +242,23 @@ 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); + flow_cntl(local_data.in_out[fd], FLOW_F_SETFL, FLOW_O_WRONLY); 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; |