[project @ 2003-07-16 17:40:38 by sof]
authorsof <unknown>
Wed, 16 Jul 2003 17:40:39 +0000 (17:40 +0000)
committersof <unknown>
Wed, 16 Jul 2003 17:40:39 +0000 (17:40 +0000)
- 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
ghc/rts/win32/IOManager.c
ghc/rts/win32/IOManager.h

index 0086696..bc153a9 100644 (file)
@@ -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;
index 42eba00..35cca1b 100644 (file)
@@ -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;
index cbdda44..686ea6c 100644 (file)
@@ -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 {