t/jobs: Fix a typo in jobs 23 & 24
[fio.git] / workqueue.c
index 254bf6b6505fd8e047021fc819b99e567d5722e4..3636bc3a8a60df765b582f8e4a889f8ef25b9769 100644 (file)
@@ -136,7 +136,8 @@ static void *worker_thread(void *data)
        sk_out_assign(sw->sk_out);
 
        if (wq->ops.nice) {
-               if (nice(wq->ops.nice) < 0) {
+               errno = 0;
+               if (nice(wq->ops.nice) == -1 && errno != 0) {
                        log_err("workqueue: nice %s\n", strerror(errno));
                        ret = 1;
                }
@@ -170,26 +171,32 @@ static void *worker_thread(void *data)
                                workqueue_pre_sleep(sw);
                                pthread_mutex_lock(&sw->lock);
                        }
-
-                       /*
-                        * We dropped and reaquired the lock, check
-                        * state again.
-                        */
-                       if (!flist_empty(&sw->work_list))
-                               goto handle_work;
-
+               }
+               /*
+                * We may have dropped and reaquired the lock, check state
+                * again.
+                */
+               if (flist_empty(&sw->work_list)) {
                        if (sw->flags & SW_F_EXIT) {
                                break;
-                       } else if (!(sw->flags & SW_F_IDLE)) {
+                       }
+                       if (!(sw->flags & SW_F_IDLE)) {
                                sw->flags |= SW_F_IDLE;
                                wq->next_free_worker = sw->index;
+                               pthread_mutex_unlock(&sw->lock);
+                               pthread_mutex_lock(&wq->flush_lock);
                                if (wq->wake_idle)
                                        pthread_cond_signal(&wq->flush_cond);
+                               pthread_mutex_unlock(&wq->flush_lock);
+                               pthread_mutex_lock(&sw->lock);
+                       }
+               }
+               if (flist_empty(&sw->work_list)) {
+                       if (sw->flags & SW_F_EXIT) {
+                               break;
                        }
-
                        pthread_cond_wait(&sw->cond, &sw->lock);
                } else {
-handle_work:
                        flist_splice_init(&sw->work_list, &local_list);
                }
                pthread_mutex_unlock(&sw->lock);