- fprintf(stderr,"worker thread (%ld): giving up RTS token\n", osThreadId()));
- releaseCapability(cap);
- RELEASE_LOCK(pMutex);
- yieldThread();
- /* At this point, pMutex has been given up & we've
- * forced a thread context switch. Guaranteed to be
- * enough for the signalled worker thread to race
- * ahead of us?
- */
-
- /* Re-grab the mutex */
- ACQUIRE_LOCK(pMutex);
+ fprintf(stderr,"worker thread (%p): giving up RTS token\n", osThreadId()));
+ releaseCapability(*pCap);
+ /* And wait for work */
+ waitForWorkCapability(pMutex, pCap, rtsFalse);
+ IF_DEBUG(scheduler,
+ fprintf(stderr,"worker thread (%p): got back RTS token (after yieldToReturningWorker)\n",
+ osThreadId()));