workqueue: properly account ->cur_depth
[fio.git] / workqueue.c
index 60e6ab2843f074742789d730ff5cde8410d4bc0c..27d1060c6e6f2b1cd6710d540e63e9b0c621691c 100644 (file)
@@ -79,7 +79,7 @@ static struct submit_worker *get_submit_worker(struct workqueue *wq)
        return sw;
 }
 
-static int all_sw_idle(struct workqueue *wq)
+static bool all_sw_idle(struct workqueue *wq)
 {
        int i;
 
@@ -87,10 +87,10 @@ static int all_sw_idle(struct workqueue *wq)
                struct submit_worker *sw = &wq->workers[i];
 
                if (!(sw->flags & SW_F_IDLE))
-                       return 0;
+                       return false;
        }
 
-       return 1;
+       return true;
 }
 
 /*
@@ -186,7 +186,7 @@ static int init_submit_worker(struct submit_worker *sw)
 
        fio_gettime(&td->epoch, NULL);
        fio_getrusage(&td->ru_start);
-       clear_io_state(td);
+       clear_io_state(td, 1);
 
        td_set_runstate(td, TD_RUNNING);
        td->flags |= TD_F_CHILD;
@@ -283,8 +283,12 @@ static void *worker_thread(void *data)
 
                        if (td->io_u_queued || td->cur_depth ||
                            td->io_u_in_flight) {
+                               int ret;
+
                                pthread_mutex_unlock(&sw->lock);
-                               io_u_quiesce(td);
+                               ret = io_u_quiesce(td);
+                               if (ret > 0)
+                                       td->cur_depth -= ret;
                                pthread_mutex_lock(&sw->lock);
                        }