From 7339bbe714ff63450f9e8ed8fbfc4a5bfe77dfb3 Mon Sep 17 00:00:00 2001
From: Pedro Gonnet <gonnet@google.com>
Date: Thu, 17 Mar 2016 23:50:19 +0100
Subject: [PATCH] wait, this was ok. the task might get consumed before the
 waiting counter is increased.

---
 src/scheduler.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/scheduler.c b/src/scheduler.c
index 3a7cc27641..af456bacf2 100644
--- a/src/scheduler.c
+++ b/src/scheduler.c
@@ -1134,12 +1134,12 @@ void scheduler_enqueue(struct scheduler *s, struct task *t) {
 
     /* If no previous owner, pick a random queue. */
     if (qid < 0) qid = rand() % s->nr_queues;
-
-    /* Insert the task into that queue. */
-    queue_insert(&s->queues[qid], t);
     
     /* Increase the waiting counter. */
     atomic_inc(&s->waiting);
+
+    /* Insert the task into that queue. */
+    queue_insert(&s->queues[qid], t);
   }
 }
 
-- 
GitLab