summaryrefslogtreecommitdiff
path: root/ghc/rts/win32/IOManager.h
diff options
context:
space:
mode:
authorsof <unknown>2003-02-21 05:34:17 +0000
committersof <unknown>2003-02-21 05:34:17 +0000
commit5b4f5a6aa8f384573f0f11bc744d5637a1f3bc09 (patch)
tree11ff6b2dd41d2c6910553437ada99a67b9d0cbb3 /ghc/rts/win32/IOManager.h
parente434189798bb3ca2125ac8978b4177511030582b (diff)
downloadhaskell-5b4f5a6aa8f384573f0f11bc744d5637a1f3bc09.tar.gz
[project @ 2003-02-21 05:34:12 by sof]
Asynchronous / non-blocking I/O for Win32 platforms. This commit introduces a Concurrent Haskell friendly view of I/O on Win32 platforms. Through the use of a pool of worker Win32 threads, CH threads may issue asynchronous I/O requests without blocking the progress of other CH threads. The issuing CH thread is blocked until the request has been serviced though. GHC.Conc exports the primops that take care of issuing the asynchronous I/O requests, which the IO implementation now takes advantage of. By default, all Handles are non-blocking/asynchronous, but should performance become an issue, having a per-Handle flag for turning off non-blocking could easily be imagined&introduced. [Incidentally, this thread pool-based implementation could easily be extended to also allow Haskell code to delegate the execution of arbitrary pieces of (potentially blocking) external code to another OS thread. Given how relatively gnarly the locking story has turned out to be with the 'threaded' RTS, that may not be such a bad idea.]
Diffstat (limited to 'ghc/rts/win32/IOManager.h')
-rw-r--r--ghc/rts/win32/IOManager.h85
1 files changed, 85 insertions, 0 deletions
diff --git a/ghc/rts/win32/IOManager.h b/ghc/rts/win32/IOManager.h
new file mode 100644
index 0000000000..3543a416ec
--- /dev/null
+++ b/ghc/rts/win32/IOManager.h
@@ -0,0 +1,85 @@
+/* IOManager.h
+ *
+ * Non-blocking / asynchronous I/O for Win32.
+ *
+ * (c) sof, 2002-2003
+ */
+#ifndef __IOMANAGER_H__
+#define __IOMANAGER_H__
+/* On the yucky side..suppress -Wmissing-declarations warnings when
+ * including <windows.h>
+ */
+extern void* GetCurrentFiber ( void );
+extern void* GetFiberData ( void );
+#include <windows.h>
+
+/*
+ The IOManager subsystem provides a non-blocking view
+ of I/O operations. It lets one (or more) OS thread(s)
+ issue multiple I/O requests, which the IOManager then
+ handles independently of/concurrent to the thread(s)
+ that issued the request. Upon completion, the issuing
+ thread can inspect the result of the I/O operation &
+ take appropriate action.
+
+ The IOManager is intended used with the GHC RTS to
+ implement non-blocking I/O in Concurrent Haskell.
+ */
+
+/*
+ * Our WorkQueue holds WorkItems, encoding IO and
+ * delay requests.
+ *
+ */
+typedef void (*CompletionProc)(unsigned int requestID,
+ void* param,
+ int fd,
+ int len,
+ char* buf,
+ int errCode);
+
+typedef struct WorkItem {
+ unsigned int workKind;
+ int fd;
+ int len;
+ char* buf;
+ void* param;
+ unsigned int requestID;
+ CompletionProc onCompletion;
+} WorkItem;
+
+extern CompletionProc onComplete;
+
+/* the kind of operations supported; you could easily imagine
+ * that instead of passing a tag describing the work to be performed,
+ * a function pointer is passed instead. Maybe later.
+ */
+#define WORKER_READ 1
+#define WORKER_WRITE 2
+#define WORKER_DELAY 4
+#define WORKER_FOR_SOCKET 8
+
+/*
+ * Starting up and shutting down.
+ */
+extern BOOL StartIOManager ( void );
+extern void ShutdownIOManager ( void );
+
+/*
+ * Adding I/O and delay requests. With each request a
+ * completion routine is supplied, which the worker thread
+ * will invoke upon completion.
+ */
+extern int AddDelayRequest ( unsigned int msecs,
+ void* data,
+ CompletionProc onCompletion);
+
+extern int AddIORequest ( int fd,
+ BOOL forWriting,
+ BOOL isSocket,
+ int len,
+ char* buffer,
+ void* data,
+ CompletionProc onCompletion);
+
+#endif /* __IOMANAGER_H__ */