From e807565a9792b31ed02e37fd837375840be6a22f Mon Sep 17 00:00:00 2001 From: simonmar Date: Thu, 18 Dec 2003 13:29:23 +0000 Subject: [PATCH] [project @ 2003-12-18 13:29:23 by simonmar] Optimisation in awaitEvent(): reset the abandonRequestWait() signal if it isn't needed (compensates for not using PulseEvent() in abandonRequestWait(), see AsyncIO.c for details). Code cleanup in awaitEvent(): don't test the various exit conditions twice. --- ghc/rts/win32/AwaitEvent.c | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/ghc/rts/win32/AwaitEvent.c b/ghc/rts/win32/AwaitEvent.c index 0df8023..92a84bc 100644 --- a/ghc/rts/win32/AwaitEvent.c +++ b/ghc/rts/win32/AwaitEvent.c @@ -25,6 +25,16 @@ awaitEvent(rtsBool wait) { int ret; +#ifdef RTS_SUPPORTS_THREADS + // Small optimisation: we don't want the waiting thread to wake + // up straight away just because a previous returning worker has + // called abandonRequestWait(). If the event is no longer needed, + // reset it. We must do this inside the sched_mutex. + if (!needToYieldToReturningWorker()) { + resetAbandonRequestWait(); + } +#endif + do { /* Try to de-queue completed IO requests */ @@ -35,28 +45,19 @@ awaitEvent(rtsBool wait) return; /* still hold the lock */ } - /* we were interrupted, return to the scheduler immediately. - */ - if (interrupted) { - return; /* still hold the lock */ - } - - /* If new runnable threads have arrived, stop waiting for - * I/O and run them. - */ - if (run_queue_hd != END_TSO_QUEUE) { - return; /* still hold the lock */ - } + // Return to the scheduler if: + // + // - we were interrupted + // - new threads have arrived + // - another worker wants to take over (RTS_SUPPORTS_THREADS) + } while (wait + && !interrupted + && run_queue_hd == END_TSO_QUEUE #ifdef RTS_SUPPORTS_THREADS - /* If another worker thread wants to take over, - * return to the scheduler - */ - if (needToYieldToReturningWorker()) { - return; /* still hold the lock */ - } + && !needToYieldToReturningWorker() #endif - } while (wait && !interrupted && run_queue_hd == END_TSO_QUEUE); + ); } #ifdef RTS_SUPPORTS_THREADS -- 1.7.10.4