X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=rts%2Fwin32%2FIOManager.c;h=c9a759fffbce2655f971f220272fb409ed7b4a06;hb=b2bd63f99d643f6b3eb30bb72bb9ae26d4183252;hp=993b1fb7170612d459cbb0a2db87bcda37210e2b;hpb=7cb50e3aea11f934fd1430c5f056f4f0f93f1f23;p=ghc-hetmet.git diff --git a/rts/win32/IOManager.c b/rts/win32/IOManager.c index 993b1fb..c9a759f 100644 --- a/rts/win32/IOManager.c +++ b/rts/win32/IOManager.c @@ -4,6 +4,9 @@ * * (c) sof, 2002-2003. */ + +#if !defined(THREADED_RTS) + #include "Rts.h" #include "IOManager.h" #include "WorkQueue.h" @@ -13,6 +16,7 @@ #include #include #include +#include /* * Internal state maintained by the IO manager. @@ -178,7 +182,15 @@ IOWorkerProc(PVOID param) len = write(work->workData.ioData.fd, work->workData.ioData.buf, work->workData.ioData.len); - if (len == -1) { errCode = errno; } + if (len == -1) { + errCode = errno; + // write() gets errno wrong for + // ERROR_NO_DATA, we have to fix it here: + if (errCode == EINVAL && + GetLastError() == ERROR_NO_DATA) { + errCode = EPIPE; + } + } } complData = work->workData.ioData.buf; fd = work->workData.ioData.fd; @@ -187,7 +199,7 @@ IOWorkerProc(PVOID param) * * Note: Sleep() is in milliseconds, not micros. */ - Sleep(work->workData.delayData.msecs / 1000); + Sleep((work->workData.delayData.msecs + 999) / 1000); len = work->workData.delayData.msecs; complData = NULL; fd = 0; @@ -340,7 +352,7 @@ depositWorkItem( unsigned int reqID, if ( (ioMan->workersIdle < ioMan->queueSize) ) { /* No, go ahead and create another. */ ioMan->numWorkers++; - if (NewIOWorkerThread(ioMan)) { + if (!NewIOWorkerThread(ioMan)) { ioMan->numWorkers--; } } @@ -440,25 +452,29 @@ AddProcRequest ( void* proc, return depositWorkItem(reqID, wItem); } -void ShutdownIOManager ( void ) +void ShutdownIOManager ( rtsBool wait_threads ) { int num; SetEvent(ioMan->hExitEvent); - /* Wait for all worker threads to die. */ - for (;;) { - EnterCriticalSection(&ioMan->manLock); - num = ioMan->numWorkers; - LeaveCriticalSection(&ioMan->manLock); - if (num == 0) - break; - Sleep(10); + if (wait_threads) { + /* Wait for all worker threads to die. */ + for (;;) { + EnterCriticalSection(&ioMan->manLock); + num = ioMan->numWorkers; + LeaveCriticalSection(&ioMan->manLock); + if (num == 0) + break; + Sleep(10); + } + FreeWorkQueue(ioMan->workQueue); + CloseHandle(ioMan->hExitEvent); + DeleteCriticalSection(&ioMan->active_work_lock); + DeleteCriticalSection(&ioMan->manLock); + free(ioMan); + ioMan = NULL; } - FreeWorkQueue(ioMan->workQueue); - CloseHandle(ioMan->hExitEvent); - free(ioMan); - ioMan = NULL; } /* Keep track of WorkItems currently being serviced. */ @@ -526,3 +542,5 @@ abandonWorkRequest ( int reqID ) */ LeaveCriticalSection(&ioMan->active_work_lock); } + +#endif