+ // Pre-condition: pMutex is held.
+
+ while ( noCapabilities() ||
+ (passingCapability && passTarget != pThreadCond) ||
+ !ANY_WORK_TO_DO()) {
+ IF_DEBUG(scheduler,
+ sched_belch("worker: wait for capability (cond: %p)",
+ pThreadCond));
+
+ if (pThreadCond != NULL) {
+ waitCondition(pThreadCond, pMutex);
+ IF_DEBUG(scheduler, sched_belch("worker: get passed capability"));
+ } else {
+ rts_n_waiting_tasks++;
+ waitCondition(&thread_ready_cond, pMutex);
+ rts_n_waiting_tasks--;
+ IF_DEBUG(scheduler, sched_belch("worker: get normal capability"));
+ }
+ }
+ passingCapability = rtsFalse;
+ grabCapability(pCap);
+
+ // Post-condition: pMutex is held and *pCap is held by the current thread
+ return;
+}
+
+/* ----------------------------------------------------------------------------
+ passCapability, passCapabilityToWorker
+ ------------------------------------------------------------------------- */
+
+void
+passCapability( Condition *pTargetThreadCond )
+{
+ // Pre-condition: pMutex is held and cap is held by the current thread
+
+ passTarget = pTargetThreadCond;
+ passingCapability = rtsTrue;
+ IF_DEBUG(scheduler, sched_belch("worker: passCapability"));
+
+ // Post-condition: pMutex is held; cap is still held, but will be
+ // passed to the target thread when next released.
+}
+
+void
+passCapabilityToWorker( void )
+{
+ // Pre-condition: pMutex is held and cap is held by the current thread
+
+ passTarget = NULL;
+ passingCapability = rtsTrue;
+ IF_DEBUG(scheduler, sched_belch("worker: passCapabilityToWorker"));
+
+ // Post-condition: pMutex is held; cap is still held, but will be
+ // passed to a worker thread when next released.