[project @ 2003-12-15 16:45:23 by simonmar]
[ghc-hetmet.git] / ghc / rts / Capability.c
index 234962b..6d2f43c 100644 (file)
@@ -69,6 +69,9 @@ Condition thread_ready_cond = INIT_COND_VAR;
  * Task.startTask() uses its current value.
  */
 nat rts_n_waiting_tasks = 0;
+
+static Condition *passTarget = NULL;
+static rtsBool passingCapability = rtsFalse;
 #endif
 
 /* -----------------------------------------------------------------------------
@@ -147,9 +150,7 @@ void grabCapability(Capability** cap)
   free_capabilities = (*cap)->link;
   rts_n_free_capabilities--;
 #endif
-#ifdef RTS_SUPPORTS_THREADS
-    IF_DEBUG(scheduler, sched_belch("worker: got capability"));
-#endif
+  IF_DEBUG(scheduler, sched_belch("worker: got capability"));
 }
 
 /*
@@ -198,10 +199,8 @@ void releaseCapability(Capability* cap
     signalCondition(&thread_ready_cond);
     startSchedulerTaskIfNecessary();  // if there is more work to be done,
                                      // we'll need a new thread
-  }
-#endif
-#ifdef RTS_SUPPORTS_THREADS
     IF_DEBUG(scheduler, sched_belch("worker: released capability"));
+  }
 #endif
   return;
 }
@@ -245,7 +244,7 @@ grabReturnCapability(Mutex* pMutex, Capability** pCap)
   IF_DEBUG(scheduler, 
           sched_belch("worker: returning; workers waiting: %d",
                       rts_n_waiting_workers));
-  if ( noCapabilities() ) {
+  if ( noCapabilities() || passingCapability ) {
     rts_n_waiting_workers++;
     wakeBlockedWorkerThread();
     context_switch = 1;        // make sure it's our turn soon
@@ -316,9 +315,6 @@ yieldToReturningWorker(Mutex* pMutex, Capability** pCap, Condition* pThreadCond)
  * Post-condition: pMutex is held and *pCap is held by the current thread
  */
  
-static Condition *passTarget = NULL;
-static rtsBool passingCapability = rtsFalse;
 void 
 waitForWorkCapability(Mutex* pMutex, Capability** pCap, Condition* pThreadCond)
 {
@@ -364,6 +360,7 @@ passCapability(Mutex* pMutex, Capability* cap, Condition *pTargetThreadCond)
 #ifdef SMP
   #error SMP version not implemented
 #endif
+    ASSERT(rts_n_free_capabilities == 0);
     rts_n_free_capabilities = 1;
     signalCondition(pTargetThreadCond);
     passTarget = pTargetThreadCond;