diff options
author | Jens Axboe <axboe@fb.com> | 2014-07-08 09:46:37 +0200 |
---|---|---|
committer | Mohamad Ayyash <mkayyash@google.com> | 2015-03-06 17:57:11 -0800 |
commit | f5fc4b423eabf5a19d1e50fd961f3e80034d76b6 (patch) | |
tree | 2a6c5afd2760ed77db14b4f08cb66566d5519cbc /mutex.c | |
parent | de6504ecd252b953c5fecf7277b4a9cc002a6602 (diff) | |
download | fio-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.c | 7 |
1 files changed, 6 insertions, 1 deletions
@@ -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) |