[project @ 2004-09-09 06:55:47 by panne]
[ghc-hetmet.git] / ghc / rts / win32 / IOManager.c
index b8b7942..c08c4e3 100644 (file)
@@ -70,6 +70,11 @@ IOWorkerProc(PVOID param)
         */
        rc = WaitForMultipleObjects( 2, hWaits, FALSE, INFINITE );
 
+       if (rc == WAIT_OBJECT_0) {
+           // we received the exit event
+           return 0;
+       }
+
        EnterCriticalSection(&iom->manLock);
        /* Signal that the thread is 'non-idle' and about to consume 
         * a work item.
@@ -78,10 +83,7 @@ IOWorkerProc(PVOID param)
        iom->queueSize--;
        LeaveCriticalSection(&iom->manLock);
     
-       if ( WAIT_OBJECT_0 == rc ) {
-           /* shutdown */
-           return 0;
-       } else if ( (WAIT_OBJECT_0 + 1) == rc ) {
+       if ( rc == (WAIT_OBJECT_0 + 1) ) {
            /* work item available, fetch it. */
            if (FetchWork(pq,(void**)&work)) {
                if ( work->workKind & WORKER_READ ) {
@@ -363,9 +365,12 @@ AddProcRequest ( void* proc,
     return depositWorkItem(reqID, wItem);
 }
 
-void ShutdownIOManager()
+void ShutdownIOManager ( void )
 {
   SetEvent(ioMan->hExitEvent);
-  free(ioMan);
-  ioMan = NULL;
+  // ToDo: we can't free this now, because the worker thread(s)
+  // haven't necessarily finished with it yet.  Perhaps it should
+  // have a reference count or something.
+  // free(ioMan);
+  // ioMan = NULL;
 }