X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Frts%2Fwin32%2FAwaitEvent.c;h=43e188fb34a8444ac14d5fe7a15c7f99ec637a58;hb=1f5e3b2472084434edf71a89c4764d1509e8e9b0;hp=a8f73fff7a13260a0c3154040132dfb4ceb39308;hpb=1897bcd13d6851873340778524f7248a057d3027;p=ghc-hetmet.git diff --git a/ghc/rts/win32/AwaitEvent.c b/ghc/rts/win32/AwaitEvent.c index a8f73ff..43e188f 100644 --- a/ghc/rts/win32/AwaitEvent.c +++ b/ghc/rts/win32/AwaitEvent.c @@ -1,3 +1,4 @@ +#if !defined(THREADED_RTS) /* to the end */ /* * Wait/check for external events. Periodically, the * Scheduler checks for the completion of external operations, @@ -14,52 +15,37 @@ */ #include "Rts.h" #include "Schedule.h" +#include "AwaitEvent.h" #include #include "win32/AsyncIO.h" -#if defined(RTS_SUPPORTS_THREADS) -#include "Capability.h" -#endif + +// Used to avoid calling abandonRequestWait() if we don't need to. +// Protected by sched_mutex. +static nat workerWaitingForRequests = 0; void awaitEvent(rtsBool wait) { - RELEASE_LOCK(&sched_mutex); - do { - /* Try to de-queue completed IO requests */ - if (!awaitRequests(wait)) { - return; - } - ACQUIRE_LOCK(&sched_mutex); - /* we were interrupted, return to the scheduler immediately. - */ - if (interrupted) { - return; /* still hold the lock */ - } + int ret; - /* If new runnable threads have arrived, stop waiting for - * I/O and run them. + do { + /* Try to de-queue completed IO requests */ - if (run_queue_hd != END_TSO_QUEUE) { + workerWaitingForRequests = 1; + ret = awaitRequests(wait); + workerWaitingForRequests = 0; + if (!ret) { return; /* still hold the lock */ } -#ifdef RTS_SUPPORTS_THREADS - /* If another worker thread wants to take over, - * return to the scheduler - */ - if (needToYieldToReturningWorker()) { - return; /* still hold the lock */ - } -#endif - RELEASE_LOCK(&sched_mutex); - } while (wait && !interrupted && run_queue_hd == END_TSO_QUEUE); -} + // Return to the scheduler if: + // + // - we were interrupted + // - new threads have arrived -#ifdef RTS_SUPPORTS_THREADS -void -wakeBlockedWorkerThread() -{ - abandonRequestWait(); + } while (wait + && sched_state == SCHED_RUNNING + && emptyRunQueue(&MainCapability) + ); } #endif -