From: Jens Axboe Date: Sat, 17 Mar 2018 20:43:16 +0000 (-0600) Subject: Merge branch 'pthread-cond' of https://github.com/bvanassche/fio X-Git-Tag: fio-3.6~39 X-Git-Url: https://git.kernel.dk/?a=commitdiff_plain;h=8d7632aa5a5a5c866ff2872319056df4ac2541ed;hp=69b98f11d62cb12482130fac79b8ebf00c0bb139;p=fio.git Merge branch 'pthread-cond' of https://github.com/bvanassche/fio * 'pthread-cond' of https://github.com/bvanassche/fio: Signal td->free_cond with the associated mutex held Make sure that assert() expressions do not have side effects --- diff --git a/io_u.c b/io_u.c index 01b36938..f3b59322 100644 --- a/io_u.c +++ b/io_u.c @@ -856,8 +856,8 @@ void put_io_u(struct thread_data *td, struct io_u *io_u) assert(!(td->flags & TD_F_CHILD)); } io_u_qpush(&td->io_u_freelist, io_u); - td_io_u_unlock(td); td_io_u_free_notify(td); + td_io_u_unlock(td); } void clear_io_u(struct thread_data *td, struct io_u *io_u) @@ -889,8 +889,8 @@ void requeue_io_u(struct thread_data *td, struct io_u **io_u) } io_u_rpush(&td->io_u_requeues, __io_u); - td_io_u_unlock(td); td_io_u_free_notify(td); + td_io_u_unlock(td); *io_u = NULL; } @@ -1558,6 +1558,7 @@ bool queue_full(const struct thread_data *td) struct io_u *__get_io_u(struct thread_data *td) { struct io_u *io_u = NULL; + int ret; if (td->stop_io) return NULL; @@ -1594,7 +1595,8 @@ again: * return one */ assert(!(td->flags & TD_F_CHILD)); - assert(!pthread_cond_wait(&td->free_cond, &td->io_u_lock)); + ret = pthread_cond_wait(&td->free_cond, &td->io_u_lock); + assert(ret == 0); goto again; } diff --git a/verify.c b/verify.c index 17af3bb9..d10670bb 100644 --- a/verify.c +++ b/verify.c @@ -1454,9 +1454,9 @@ static void *verify_async_thread(void *data) done: pthread_mutex_lock(&td->io_u_lock); td->nr_verify_threads--; + pthread_cond_signal(&td->free_cond); pthread_mutex_unlock(&td->io_u_lock); - pthread_cond_signal(&td->free_cond); return NULL; } @@ -1492,9 +1492,12 @@ int verify_async_init(struct thread_data *td) if (i != td->o.verify_async) { log_err("fio: only %d verify threads started, exiting\n", i); + + pthread_mutex_lock(&td->io_u_lock); td->verify_thread_exit = 1; - write_barrier(); pthread_cond_broadcast(&td->verify_cond); + pthread_mutex_unlock(&td->io_u_lock); + return 1; } @@ -1503,12 +1506,10 @@ int verify_async_init(struct thread_data *td) void verify_async_exit(struct thread_data *td) { + pthread_mutex_lock(&td->io_u_lock); td->verify_thread_exit = 1; - write_barrier(); pthread_cond_broadcast(&td->verify_cond); - pthread_mutex_lock(&td->io_u_lock); - while (td->nr_verify_threads) pthread_cond_wait(&td->free_cond, &td->io_u_lock);