X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Frts%2FCapability.c;h=d8bdbe6b50fb2965b023fa9bb884eff7112de158;hb=e0b2097136f30331bae67cb01e66bba749d272c1;hp=2dec782fd90f269b34c31af41f6c73a08fddedf3;hpb=6d7576ef2853317e690a7c4e823d7f0bb8d9aaf0;p=ghc-hetmet.git diff --git a/ghc/rts/Capability.c b/ghc/rts/Capability.c index 2dec782..d8bdbe6 100644 --- a/ghc/rts/Capability.c +++ b/ghc/rts/Capability.c @@ -68,8 +68,8 @@ Condition thread_ready_cond = INIT_COND_VAR; * the number of tasks currently blocked waiting on thread_ready_cond. * (if > 0 => no need for a new task, just unblock an existing one). * - * waitForWork() takes care of keeping it up-to-date; Task.startTask() - * uses its current value. + * waitForWorkCapability() takes care of keeping it up-to-date; + * Task.startTask() uses its current value. */ nat rts_n_waiting_tasks = 0; #endif @@ -214,13 +214,13 @@ void releaseCapability(Capability* cap * Function: grabReturnCapability(Capability**) * * Purpose: when an OS thread returns from an external call, - * it calls grabReturningCapability() (via Schedule.resumeThread()) + * it calls grabReturnCapability() (via Schedule.resumeThread()) * to wait for permissions to enter the RTS & communicate the - * result of the ext. call back to the Haskell thread that + * result of the external call back to the Haskell thread that * made it. * - * Pre-condition: pMutex isn't held. - * Post-condition: pMutex is held and a capability has + * Pre-condition: pMutex is held. + * Post-condition: pMutex is still held and a capability has * been assigned to the worker thread. */ void @@ -228,7 +228,6 @@ grabReturnCapability(Mutex* pMutex, Capability** pCap) { IF_DEBUG(scheduler, fprintf(stderr,"worker (%ld): returning, waiting for lock.\n", osThreadId())); - ACQUIRE_LOCK(pMutex); rts_n_waiting_workers++; IF_DEBUG(scheduler, fprintf(stderr,"worker (%ld): returning; workers waiting: %d\n", @@ -260,22 +259,14 @@ grabReturnCapability(Mutex* pMutex, Capability** pCap) * been given back. */ void -yieldToReturningWorker(Mutex* pMutex, Capability* cap) +yieldToReturningWorker(Mutex* pMutex, Capability** pCap) { if ( rts_n_waiting_workers > 0 && noCapabilities() ) { IF_DEBUG(scheduler, 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); + releaseCapability(*pCap); + /* And wait for work */ + waitForWorkCapability(pMutex, pCap, rtsFalse); } return; }