small optimisation for the program in #5367: if the worker thread
authorSimon Marlow <marlowsd@gmail.com>
Wed, 3 Aug 2011 12:41:33 +0000 (13:41 +0100)
committerSimon Marlow <marlowsd@gmail.com>
Fri, 5 Aug 2011 08:21:49 +0000 (09:21 +0100)
being woken already has its wakeup flag set, don't bother signalling
its condition variable again.

rts/Capability.c

index 91c5e2d..57c75e6 100644 (file)
@@ -366,11 +366,13 @@ giveCapabilityToTask (Capability *cap USED_IF_DEBUG, Task *task)
                cap->no, task->incall->tso ? "bound task" : "worker",
                (void *)task->id);
     ACQUIRE_LOCK(&task->lock);
-    task->wakeup = rtsTrue;
-    // the wakeup flag is needed because signalCondition() doesn't
-    // flag the condition if the thread is already runniing, but we want
-    // it to be sticky.
-    signalCondition(&task->cond);
+    if (task->wakeup == rtsFalse) {
+        task->wakeup = rtsTrue;
+        // the wakeup flag is needed because signalCondition() doesn't
+        // flag the condition if the thread is already runniing, but we want
+        // it to be sticky.
+        signalCondition(&task->cond);
+    }
     RELEASE_LOCK(&task->lock);
 }
 #endif