From dfe5a46fb5315112d1173ac983ffc416dc3ecf18 Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Sun, 22 May 2016 14:53:22 +0200 Subject: lib, ipcpd, irmd: fixes deallocation and fast path The fast path has been rewritten to have certainty to read the correct flow. Deallocation will not release port_id's or fd's until they are explicitly released locally. --- src/lib/dev.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'src/lib/dev.c') diff --git a/src/lib/dev.c b/src/lib/dev.c index d332a27f..1332b014 100644 --- a/src/lib/dev.c +++ b/src/lib/dev.c @@ -300,6 +300,7 @@ int flow_accept(int fd, rw_lock_rdlock(&_ap_instance->data_lock); rw_lock_wrlock(&_ap_instance->flows_lock); + cfd = bmp_allocate(_ap_instance->fds); if (!bmp_is_id_valid(_ap_instance->fds, cfd)) { rw_lock_unlock(&_ap_instance->flows_lock); @@ -588,37 +589,39 @@ ssize_t flow_write(int fd, void * buf, size_t count) ssize_t flow_read(int fd, void * buf, size_t count) { - struct rb_entry * e = NULL; + int idx = -1; int n; uint8_t * sdu; rw_lock_rdlock(&_ap_instance->data_lock); rw_lock_rdlock(&_ap_instance->flows_lock); + if (_ap_instance->flows[fd].port_id < 0) { + rw_lock_unlock(&_ap_instance->flows_lock); + rw_lock_unlock(&_ap_instance->data_lock); + return -1; + } + if (_ap_instance->flows[fd].oflags & FLOW_O_NONBLOCK) { - if (shm_ap_rbuff_peek(_ap_instance->rb) - != _ap_instance->flows[fd].port_id) { - rw_lock_unlock(&_ap_instance->flows_lock); - rw_lock_unlock(&_ap_instance->data_lock); - return -1; - } + idx = shm_ap_rbuff_read_port(_ap_instance->rb, + _ap_instance->flows[fd].port_id); } else { /* block */ - while (shm_ap_rbuff_peek(_ap_instance->rb) - != _ap_instance->flows[fd].port_id) + while ((idx = shm_ap_rbuff_read_port( + _ap_instance->rb, + _ap_instance->flows[fd].port_id)) < 0) ; } rw_lock_unlock(&_ap_instance->flows_lock); - e = shm_ap_rbuff_read(_ap_instance->rb); - if (e == NULL) { + if (idx < 0) { rw_lock_unlock(&_ap_instance->data_lock); return -1; } n = shm_du_map_read_sdu(&sdu, _ap_instance->dum, - e->index); + idx); if (n < 0) { rw_lock_unlock(&_ap_instance->data_lock); return -1; @@ -626,7 +629,7 @@ ssize_t flow_read(int fd, void * buf, size_t count) memcpy(buf, sdu, MIN(n, count)); - shm_release_du_buff(_ap_instance->dum, e->index); + shm_release_du_buff(_ap_instance->dum, idx); rw_lock_unlock(&_ap_instance->data_lock); -- cgit v1.2.3