summaryrefslogtreecommitdiff
path: root/mutex.c
diff options
context:
space:
mode:
authorJens Axboe <axboe@fb.com>2014-07-08 09:46:37 +0200
committerMohamad Ayyash <mkayyash@google.com>2015-03-06 17:57:11 -0800
commitf5fc4b423eabf5a19d1e50fd961f3e80034d76b6 (patch)
tree2a6c5afd2760ed77db14b4f08cb66566d5519cbc /mutex.c
parentde6504ecd252b953c5fecf7277b4a9cc002a6602 (diff)
downloadfio-f5fc4b423eabf5a19d1e50fd961f3e80034d76b6.tar.gz
mutex: move pthread_cond_signal() outside of lock
Generally best practice to drop the lock before waking, if possible. Signed-off-by: Jens Axboe <axboe@fb.com>
Diffstat (limited to 'mutex.c')
-rw-r--r--mutex.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/mutex.c b/mutex.c
index 9d10c2ce..9ee3bd83 100644
--- a/mutex.c
+++ b/mutex.c
@@ -162,14 +162,19 @@ void fio_mutex_down(struct fio_mutex *mutex)
void fio_mutex_up(struct fio_mutex *mutex)
{
+ int do_wake = 0;
+
assert(mutex->magic == FIO_MUTEX_MAGIC);
pthread_mutex_lock(&mutex->lock);
read_barrier();
if (!mutex->value && mutex->waiters)
- pthread_cond_signal(&mutex->cond);
+ do_wake = 1;
mutex->value++;
pthread_mutex_unlock(&mutex->lock);
+
+ if (do_wake)
+ pthread_cond_signal(&mutex->cond);
}
void fio_rwlock_write(struct fio_rwlock *lock)