From 788897b6bdcc4d3275a7e72d501d60eddf8abe49 Mon Sep 17 00:00:00 2001 From: sof Date: Wed, 16 Jul 2003 17:40:39 +0000 Subject: [PATCH] [project @ 2003-07-16 17:40:38 by sof] - change prototype of async proc calls to typedef int (*DoProcProc)(void *param); i.e., have the proc return a result. Turned out that almost all uses of the primop ended up encoding a result via their 'param'. - when adding new I/O requests, shorten the time the IOManager lock is held. Helps to keep down the size of the thread pool. --- ghc/rts/win32/AsyncIO.c | 2 +- ghc/rts/win32/IOManager.c | 21 ++++++++++++++++----- ghc/rts/win32/IOManager.h | 7 ++++++- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/ghc/rts/win32/AsyncIO.c b/ghc/rts/win32/AsyncIO.c index 0086696..bc153a9 100644 --- a/ghc/rts/win32/AsyncIO.c +++ b/ghc/rts/win32/AsyncIO.c @@ -205,7 +205,7 @@ start: */ tso->block_info.async_result->len = completedTable[i].len; tso->block_info.async_result->errCode = completedTable[i].errCode; - + /* Drop the matched TSO from blocked_queue */ if (prev) { prev->link = tso->link; diff --git a/ghc/rts/win32/IOManager.c b/ghc/rts/win32/IOManager.c index 42eba00..35cca1b 100644 --- a/ghc/rts/win32/IOManager.c +++ b/ghc/rts/win32/IOManager.c @@ -120,8 +120,7 @@ IOWorkerProc(PVOID param) /* The procedure is assumed to encode result + success/failure * via its param. */ - work->workData.procData.proc(work->workData.procData.param); - errCode=0; + errCode=work->workData.procData.proc(work->workData.procData.param); } else { errCode=1; } @@ -234,9 +233,11 @@ AddIORequest ( int fd, #endif if ( ioMan->workersIdle == 0 ) { ioMan->numWorkers++; + LeaveCriticalSection(&ioMan->manLock); NewIOWorkerThread(ioMan); + } else { + LeaveCriticalSection(&ioMan->manLock); } - LeaveCriticalSection(&ioMan->manLock); if (SubmitWork(ioMan->workQueue,wItem)) { return wItem->requestID; @@ -263,11 +264,16 @@ AddDelayRequest ( unsigned int msecs, wItem->requestID = ioMan->requestID++; EnterCriticalSection(&ioMan->manLock); +#if 0 + fprintf(stderr, "AddDelayRequest: %d\n", ioMan->workersIdle); fflush(stderr); +#endif if ( ioMan->workersIdle == 0 ) { ioMan->numWorkers++; + LeaveCriticalSection(&ioMan->manLock); NewIOWorkerThread(ioMan); + } else { + LeaveCriticalSection(&ioMan->manLock); } - LeaveCriticalSection(&ioMan->manLock); if (SubmitWork(ioMan->workQueue,wItem)) { return wItem->requestID; @@ -296,11 +302,16 @@ AddProcRequest ( void* proc, wItem->requestID = ioMan->requestID++; EnterCriticalSection(&ioMan->manLock); +#if 0 + fprintf(stderr, "AddProcRequest: %d\n", ioMan->workersIdle); fflush(stderr); +#endif if ( ioMan->workersIdle == 0 ) { ioMan->numWorkers++; + LeaveCriticalSection(&ioMan->manLock); NewIOWorkerThread(ioMan); + } else { + LeaveCriticalSection(&ioMan->manLock); } - LeaveCriticalSection(&ioMan->manLock); if (SubmitWork(ioMan->workQueue,wItem)) { return wItem->requestID; diff --git a/ghc/rts/win32/IOManager.h b/ghc/rts/win32/IOManager.h index cbdda44..686ea6c 100644 --- a/ghc/rts/win32/IOManager.h +++ b/ghc/rts/win32/IOManager.h @@ -37,7 +37,12 @@ typedef void (*CompletionProc)(unsigned int requestID, void* buf, int errCode); -typedef void (*DoProcProc)(void *param); +/* + * Asynchronous procedure calls executed by a worker thread + * take a generic state argument pointer and return an int by + * default. + */ +typedef int (*DoProcProc)(void *param); typedef union workData { struct { -- 1.7.10.4