diff options
author | dimitri staessens <[email protected]> | 2016-05-14 13:26:27 +0200 |
---|---|---|
committer | dimitri staessens <[email protected]> | 2016-05-14 13:26:27 +0200 |
commit | c56a4ed3b865b4b240c6f01809c935b7b86d160b (patch) | |
tree | 5e5b531eeaea21bcbebbb69607f82f0ae8f96c87 | |
parent | 6fa44063041765df752cdcf81ae990e47a37681a (diff) | |
download | ouroboros-c56a4ed3b865b4b240c6f01809c935b7b86d160b.tar.gz ouroboros-c56a4ed3b865b4b240c6f01809c935b7b86d160b.zip |
lib: fixed a bug in the rw_lock
Locking the main mutex should happen while the counter is locked.
-rw-r--r-- | src/lib/rw_lock.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/lib/rw_lock.c b/src/lib/rw_lock.c index cf471e60..ba285694 100644 --- a/src/lib/rw_lock.c +++ b/src/lib/rw_lock.c @@ -70,6 +70,8 @@ int rw_lock_rdlock(rw_lock_t * lock) int rw_lock_wrlock(rw_lock_t * lock) { + int ret = 0; + if (lock == NULL) return -1; @@ -86,6 +88,8 @@ int rw_lock_wrlock(rw_lock_t * lock) pthread_mutex_lock(&lock->i_lock); if (lock->i == 0) { + ++(lock->i); + ret = pthread_mutex_lock(&lock->lock); pthread_mutex_unlock(&lock->i_lock); break; } @@ -95,9 +99,7 @@ int rw_lock_wrlock(rw_lock_t * lock) sched_yield(); } - ++(lock->i); - - return pthread_mutex_lock(&lock->lock); + return ret; } int rw_lock_unlock(rw_lock_t * lock) |