diff options
author | dimitri staessens <dimitri.staessens@ugent.be> | 2017-03-29 13:11:49 +0200 |
---|---|---|
committer | dimitri staessens <dimitri.staessens@ugent.be> | 2017-03-29 13:11:49 +0200 |
commit | 3896a4d3e8634470557ea72ded70e7d9e33b7741 (patch) | |
tree | 7e5714b5be41b8ebda807fcca71d084dcf1b9234 /src/lib | |
parent | 99b9bd5273e6f7bbbaf4973ef15977ac7056b02d (diff) | |
download | ouroboros-3896a4d3e8634470557ea72ded70e7d9e33b7741.tar.gz ouroboros-3896a4d3e8634470557ea72ded70e7d9e33b7741.zip |
lib: Fix locks in dev.c
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/dev.c | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/src/lib/dev.c b/src/lib/dev.c index bd706dc8..79797b92 100644 --- a/src/lib/dev.c +++ b/src/lib/dev.c @@ -1394,6 +1394,7 @@ int ipcp_flow_read(int fd, { ssize_t idx = -1; int port_id = -1; + struct shm_rbuff * rb; pthread_rwlock_rdlock(&ai.data_lock); pthread_rwlock_rdlock(&ai.flows_lock); @@ -1404,22 +1405,19 @@ int ipcp_flow_read(int fd, return -ENOTALLOC; } + rb = ai.flows[fd].rx_rb; + pthread_rwlock_unlock(&ai.flows_lock); pthread_rwlock_unlock(&ai.data_lock); - idx = shm_rbuff_read(ai.flows[fd].rx_rb); - if (idx < 0) { - pthread_rwlock_rdlock(&ai.data_lock); - pthread_rwlock_rdlock(&ai.flows_lock); + idx = shm_rbuff_read(rb); + if (idx < 0) return idx; - } pthread_rwlock_rdlock(&ai.data_lock); - pthread_rwlock_rdlock(&ai.flows_lock); *sdb = shm_rdrbuff_get(ai.rdrb, idx); - pthread_rwlock_unlock(&ai.flows_lock); pthread_rwlock_unlock(&ai.data_lock); return 0; |