From e4ccf13bad6de387704690215359978731d1015b Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Fri, 9 Mar 2018 07:55:40 -0700 Subject: [PATCH] mutex: ensure that fio_mutex_up() holds mutex lock during wakeup Some implementations mandate that you hold the lock while issuing the wakeup, as not to lose a wakeup. This seems to be the case for Windows. See the lengthy thread on the topic here: https://www.spinics.net/lists/fio/msg06772.html Thanks to Sitsofe Wheeler for heroic debugging. Reported-by: Rebecca Cran Signed-off-by: Jens Axboe --- mutex.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mutex.c b/mutex.c index 63229eda..acc88dc3 100644 --- a/mutex.c +++ b/mutex.c @@ -240,10 +240,11 @@ void fio_mutex_up(struct fio_mutex *mutex) if (!mutex->value && mutex->waiters) do_wake = 1; mutex->value++; - pthread_mutex_unlock(&mutex->lock); if (do_wake) pthread_cond_signal(&mutex->cond); + + pthread_mutex_unlock(&mutex->lock); } void fio_rwlock_write(struct fio_rwlock *lock) -- 2.25.1