[project @ 2003-07-16 17:40:38 by sof]
[ghc-hetmet.git] / ghc / rts / win32 / IOManager.h
1 /* IOManager.h
2  *
3  * Non-blocking / asynchronous I/O for Win32.
4  *
5  * (c) sof, 2002-2003
6  */
7 #ifndef __IOMANAGER_H__
8 #define __IOMANAGER_H__
9 /* On the yucky side..suppress -Wmissing-declarations warnings when
10  * including <windows.h>
11  */
12 extern void* GetCurrentFiber ( void );
13 extern void* GetFiberData ( void );
14 #include <windows.h>
15
16 /*
17  The IOManager subsystem provides a non-blocking view
18  of I/O operations. It lets one (or more) OS thread(s)
19  issue multiple I/O requests, which the IOManager then 
20  handles independently of/concurrent to the thread(s)
21  that issued the request. Upon completion, the issuing
22  thread can inspect the result of the I/O operation &
23  take appropriate action.
24
25  The IOManager is intended used with the GHC RTS to
26  implement non-blocking I/O in Concurrent Haskell.
27  */
28
29 /*
30  * Our WorkQueue holds WorkItems, encoding IO and
31  * delay requests.
32  *
33  */
34 typedef void (*CompletionProc)(unsigned int requestID,
35                                int   fd,
36                                int   len,
37                                void* buf,
38                                int   errCode);
39
40 /* 
41  * Asynchronous procedure calls executed by a worker thread
42  * take a generic state argument pointer and return an int by 
43  * default. 
44  */
45 typedef int (*DoProcProc)(void *param);
46
47 typedef union workData {
48     struct {
49         int   fd;
50         int   len;
51         char *buf; 
52     } ioData;
53     struct { 
54         int   msecs;
55     } delayData;
56     struct { 
57         DoProcProc proc;
58         void* param;
59     } procData;
60 } WorkData;
61
62 typedef struct WorkItem {
63   unsigned int   workKind;
64   WorkData       workData;
65   unsigned int   requestID;
66   CompletionProc onCompletion;
67 } WorkItem;
68
69 extern CompletionProc onComplete;
70
71 /* the kind of operations supported; you could easily imagine
72  * that instead of passing a tag describing the work to be performed,
73  * a function pointer is passed instead. Maybe later.
74  */
75 #define WORKER_READ        1
76 #define WORKER_WRITE       2
77 #define WORKER_DELAY       4
78 #define WORKER_FOR_SOCKET  8
79 #define WORKER_DO_PROC    16
80
81 /*
82  * Starting up and shutting down. 
83  */ 
84 extern BOOL StartIOManager     ( void );
85 extern void ShutdownIOManager  ( void );
86
87 /*
88  * Adding I/O and delay requests. With each request a
89  * completion routine is supplied, which the worker thread
90  * will invoke upon completion.
91  */
92 extern int AddDelayRequest ( unsigned int   msecs,
93                              CompletionProc onCompletion);
94
95 extern int AddIORequest ( int            fd,
96                           BOOL           forWriting,
97                           BOOL           isSocket,
98                           int            len,
99                           char*          buffer,
100                           CompletionProc onCompletion);
101
102 extern int AddProcRequest ( void*          proc,
103                             void*          data,
104                             CompletionProc onCompletion);
105
106 #endif /* __IOMANAGER_H__ */