From 622da08564f02443b40426a19c25f82e89071cac Mon Sep 17 00:00:00 2001 From: simonmar Date: Mon, 15 Dec 2003 14:31:48 +0000 Subject: [PATCH] [project @ 2003-12-15 14:31:48 by simonmar] Fix locking bug in awaitEvent(): in one code path it could return with sched_lock unlocked. --- ghc/rts/win32/AwaitEvent.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/ghc/rts/win32/AwaitEvent.c b/ghc/rts/win32/AwaitEvent.c index a8f73ff..0df8023 100644 --- a/ghc/rts/win32/AwaitEvent.c +++ b/ghc/rts/win32/AwaitEvent.c @@ -23,13 +23,18 @@ void awaitEvent(rtsBool wait) { - RELEASE_LOCK(&sched_mutex); + int ret; + do { - /* Try to de-queue completed IO requests */ - if (!awaitRequests(wait)) { - return; - } + /* Try to de-queue completed IO requests + */ + RELEASE_LOCK(&sched_mutex); + ret = awaitRequests(wait); ACQUIRE_LOCK(&sched_mutex); + if (!ret) { + return; /* still hold the lock */ + } + /* we were interrupted, return to the scheduler immediately. */ if (interrupted) { @@ -51,7 +56,6 @@ awaitEvent(rtsBool wait) return; /* still hold the lock */ } #endif - RELEASE_LOCK(&sched_mutex); } while (wait && !interrupted && run_queue_hd == END_TSO_QUEUE); } -- 1.7.10.4