From: Jens Axboe Date: Fri, 9 Mar 2018 14:55:40 +0000 (-0700) Subject: mutex: ensure that fio_mutex_up() holds mutex lock during wakeup X-Git-Tag: fio-3.6~52 X-Git-Url: https://git.kernel.dk/?p=fio.git;a=commitdiff_plain;h=e4ccf13bad6de387704690215359978731d1015b 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 --- 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)