[project @ 2003-07-23 13:08:55 by simonpj]
[ghc-hetmet.git] / ghc / rts / win32 / AsyncIO.c
index b823308..bc153a9 100644 (file)
@@ -5,6 +5,7 @@
  * (c) sof, 2002-2003.
  */
 #include "Rts.h"
+#include "RtsUtils.h"
 #include <windows.h>
 #include <stdio.h>
 #include "Schedule.h"
@@ -51,10 +52,9 @@ static int              issued_reqs;
 
 static void
 onIOComplete(unsigned int reqID,
-            void* param STG_UNUSED,
             int   fd STG_UNUSED,
             int   len,
-            char* buf STG_UNUSED,
+            void* buf STG_UNUSED,
             int   errCode)
 {
   /* Deposit result of request in queue/table */
@@ -96,21 +96,34 @@ addIORequest(int   fd,
 #if 0
   fprintf(stderr, "addIOReq: %d %d %d\n", fd, forWriting, len); fflush(stderr);
 #endif
-  return AddIORequest(fd,forWriting,isSock,len,buf,0,onIOComplete);
+  return AddIORequest(fd,forWriting,isSock,len,buf,onIOComplete);
 }
 
 unsigned int
-addDelayRequest(int   msecs)
+addDelayRequest(int msecs)
 {
   EnterCriticalSection(&queue_lock);
   issued_reqs++;
   LeaveCriticalSection(&queue_lock);
 #if 0
-  fprintf(stderr, "addDelayReq: %d %d %d\n", msecs); fflush(stderr);
+  fprintf(stderr, "addDelayReq: %d\n", msecs); fflush(stderr);
 #endif
-  return AddDelayRequest(msecs,0,onIOComplete);
+  return AddDelayRequest(msecs,onIOComplete);
 }
 
+unsigned int
+addDoProcRequest(void* proc, void* param)
+{
+  EnterCriticalSection(&queue_lock);
+  issued_reqs++;
+  LeaveCriticalSection(&queue_lock);
+#if 0
+  fprintf(stderr, "addProcReq: %p %p\n", proc, param); fflush(stderr);
+#endif
+  return AddProcRequest(proc,param,onIOComplete);
+}
+
+
 int
 startupAsyncIO()
 {
@@ -183,17 +196,15 @@ start:
       prev = NULL;
       for(tso = blocked_queue_hd ; tso != END_TSO_QUEUE; tso = tso->link) {
        switch(tso->why_blocked) {
-       case BlockedOnDelay:
        case BlockedOnRead:
        case BlockedOnWrite:
+       case BlockedOnDoProc:
          if (tso->block_info.async_result->reqID == rID) {
            /* Found the thread blocked waiting on request; stodgily fill 
             * in its result block. 
             */
-           if (tso->why_blocked != BlockedOnDelay) {
-             tso->block_info.async_result->len = completedTable[i].len;
-             tso->block_info.async_result->errCode = completedTable[i].errCode;
-           }
+           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) {
@@ -212,6 +223,9 @@ start:
          }
          break;
        default:
+         if (tso->why_blocked != NotBlocked) {
+             barf("awaitRequests: odd thread state");
+         }
          break;
        }
        prev = tso;