Signal td->free_cond with the associated mutex held
[fio.git] / io_u.c
diff --git a/io_u.c b/io_u.c
index 89eacd3bdd20ac9699d2aacc25284881296af171..f3b593227043626d6978005c35ebec5c5a6472dc 100644 (file)
--- a/io_u.c
+++ b/io_u.c
@@ -430,7 +430,11 @@ static int get_next_seq_offset(struct thread_data *td, struct fio_file *f,
        if (f->last_pos[ddir] < f->real_file_size) {
                uint64_t pos;
 
-               if (f->last_pos[ddir] == f->file_offset && o->ddir_seq_add < 0) {
+               /*
+                * Only rewind if we already hit the end
+                */
+               if (f->last_pos[ddir] == f->file_offset &&
+                   f->file_offset && o->ddir_seq_add < 0) {
                        if (f->real_file_size > f->io_size)
                                f->last_pos[ddir] = f->io_size;
                        else
@@ -470,7 +474,7 @@ static int get_next_seq_offset(struct thread_data *td, struct fio_file *f,
 
 static int get_next_block(struct thread_data *td, struct io_u *io_u,
                          enum fio_ddir ddir, int rw_seq,
-                         unsigned int *is_random)
+                         bool *is_random)
 {
        struct fio_file *f = io_u->file;
        uint64_t b, offset;
@@ -484,27 +488,27 @@ static int get_next_block(struct thread_data *td, struct io_u *io_u,
                if (td_random(td)) {
                        if (should_do_random(td, ddir)) {
                                ret = get_next_rand_block(td, f, ddir, &b);
-                               *is_random = 1;
+                               *is_random = true;
                        } else {
-                               *is_random = 0;
+                               *is_random = false;
                                io_u_set(td, io_u, IO_U_F_BUSY_OK);
                                ret = get_next_seq_offset(td, f, ddir, &offset);
                                if (ret)
                                        ret = get_next_rand_block(td, f, ddir, &b);
                        }
                } else {
-                       *is_random = 0;
+                       *is_random = false;
                        ret = get_next_seq_offset(td, f, ddir, &offset);
                }
        } else {
                io_u_set(td, io_u, IO_U_F_BUSY_OK);
-               *is_random = 0;
+               *is_random = false;
 
                if (td->o.rw_seq == RW_SEQ_SEQ) {
                        ret = get_next_seq_offset(td, f, ddir, &offset);
                        if (ret) {
                                ret = get_next_rand_block(td, f, ddir, &b);
-                               *is_random = 0;
+                               *is_random = false;
                        }
                } else if (td->o.rw_seq == RW_SEQ_IDENT) {
                        if (f->last_start[ddir] != -1ULL)
@@ -538,7 +542,7 @@ static int get_next_block(struct thread_data *td, struct io_u *io_u,
  * the last io issued.
  */
 static int get_next_offset(struct thread_data *td, struct io_u *io_u,
-                          unsigned int *is_random)
+                          bool *is_random)
 {
        struct fio_file *f = io_u->file;
        enum fio_ddir ddir = io_u->ddir;
@@ -581,7 +585,7 @@ static inline bool io_u_fits(struct thread_data *td, struct io_u *io_u,
 }
 
 static unsigned int get_next_buflen(struct thread_data *td, struct io_u *io_u,
-                                   unsigned int is_random)
+                                   bool is_random)
 {
        int ddir = io_u->ddir;
        unsigned int buflen = 0;
@@ -592,7 +596,7 @@ static unsigned int get_next_buflen(struct thread_data *td, struct io_u *io_u,
        assert(ddir_rw(ddir));
 
        if (td->o.bs_is_seq_rand)
-               ddir = is_random ? DDIR_WRITE: DDIR_READ;
+               ddir = is_random ? DDIR_WRITE : DDIR_READ;
 
        minbs = td->o.min_bs[ddir];
        maxbs = td->o.max_bs[ddir];
@@ -852,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)
@@ -885,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;
 }
 
@@ -931,7 +935,7 @@ static void __fill_io_u_zone(struct thread_data *td, struct io_u *io_u)
 
 static int fill_io_u(struct thread_data *td, struct io_u *io_u)
 {
-       unsigned int is_random;
+       bool is_random;
 
        if (td_ioengine_flagged(td, FIO_NOIO))
                goto out;
@@ -1554,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;
@@ -1590,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;
        }