From 3896a4d3e8634470557ea72ded70e7d9e33b7741 Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Wed, 29 Mar 2017 13:11:49 +0200 Subject: lib: Fix locks in dev.c --- src/lib/dev.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'src') 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; -- cgit v1.2.3