summaryrefslogtreecommitdiff
path: root/src/lib/dev.c
diff options
context:
space:
mode:
authorSander Vrijders <[email protected]>2016-05-22 15:31:45 +0200
committerSander Vrijders <[email protected]>2016-05-22 15:31:45 +0200
commit0200dcb157be0e62eb495bc870cdac03130c2aa1 (patch)
treefe6459aadc00e81ef1252392dc07e009e3e8888e /src/lib/dev.c
parent745cc666e34d7e0c29822615987ce02832ac5a8c (diff)
parentdfe5a46fb5315112d1173ac983ffc416dc3ecf18 (diff)
downloadouroboros-0200dcb157be0e62eb495bc870cdac03130c2aa1.tar.gz
ouroboros-0200dcb157be0e62eb495bc870cdac03130c2aa1.zip
Merged in dstaesse/ouroboros/be-dealloc-full (pull request #105)
lib, ipcpd, irmd: fixes deallocation and fast path
Diffstat (limited to 'src/lib/dev.c')
-rw-r--r--src/lib/dev.c29
1 files changed, 16 insertions, 13 deletions
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);