diff options
author | dimitri staessens <dimitri.staessens@intec.ugent.be> | 2016-08-09 16:51:12 +0200 |
---|---|---|
committer | dimitri staessens <dimitri.staessens@intec.ugent.be> | 2016-08-09 16:51:12 +0200 |
commit | dc0e2a74d74f524f1d94140827d88479d42acd69 (patch) | |
tree | b2f1805087a2c1f1b22d4ff489bcb6d77d4d20fb /src | |
parent | f558d4404a9cb5b87ce3e239d8c0712bbaaba39a (diff) | |
download | ouroboros-dc0e2a74d74f524f1d94140827d88479d42acd69.tar.gz ouroboros-dc0e2a74d74f524f1d94140827d88479d42acd69.zip |
lib: dev.c: Release locks before blocking calls
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/dev.c | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/src/lib/dev.c b/src/lib/dev.c index 3c31ce6d..cc332233 100644 --- a/src/lib/dev.c +++ b/src/lib/dev.c @@ -503,12 +503,21 @@ ssize_t flow_write(int fd, void * buf, size_t count) return -1; } } else { /* blocking */ - idx = shm_du_map_write_b(_ap_instance->dum, - _ap_instance->flows[fd].api, + struct shm_du_map * dum = _ap_instance->dum; + pid_t api = _ap_instance->flows[fd].api; + pthread_rwlock_unlock(&_ap_instance->flows_lock); + pthread_rwlock_unlock(&_ap_instance->data_lock); + + idx = shm_du_map_write_b(dum, + api, DU_BUFF_HEADSPACE, DU_BUFF_TAILSPACE, (uint8_t *) buf, count); + + pthread_rwlock_rdlock(&_ap_instance->data_lock); + pthread_rwlock_rdlock(&_ap_instance->flows_lock); + e.index = idx; e.port_id = _ap_instance->flows[fd].port_id; @@ -548,15 +557,21 @@ ssize_t flow_read(int fd, void * buf, size_t count) return -ENOTALLOC; } - if (_ap_instance->flows[fd].oflags & FLOW_O_NONBLOCK) + if (_ap_instance->flows[fd].oflags & FLOW_O_NONBLOCK) { idx = shm_ap_rbuff_read_port(_ap_instance->rb, _ap_instance->flows[fd].port_id); - else - idx = shm_ap_rbuff_read_port_b(_ap_instance->rb, - _ap_instance->flows[fd].port_id, - _ap_instance->flows[fd].timeout); + pthread_rwlock_unlock(&_ap_instance->flows_lock); + } else { + struct shm_ap_rbuff * rb = _ap_instance->rb; + int port_id = _ap_instance->flows[fd].port_id; + struct timespec * timeout = _ap_instance->flows[fd].timeout; + pthread_rwlock_unlock(&_ap_instance->flows_lock); + pthread_rwlock_unlock(&_ap_instance->data_lock); - pthread_rwlock_unlock(&_ap_instance->flows_lock); + idx = shm_ap_rbuff_read_port_b(rb, port_id, timeout); + + pthread_rwlock_rdlock(&_ap_instance->data_lock); + } if (idx < 0) { pthread_rwlock_unlock(&_ap_instance->data_lock); |