cbdda44a69fdbc1558c14ca9ad9016ccda07fcc4
[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 typedef void (*DoProcProc)(void *param);
41
42 typedef union workData {
43     struct {
44         int   fd;
45         int   len;
46         char *buf; 
47     } ioData;
48     struct { 
49         int   msecs;
50     } delayData;
51     struct { 
52         DoProcProc proc;
53         void* param;
54     } procData;
55 } WorkData;
56
57 typedef struct WorkItem {
58   unsigned int   workKind;
59   WorkData       workData;
60   unsigned int   requestID;
61   CompletionProc onCompletion;
62 } WorkItem;
63
64 extern CompletionProc onComplete;
65
66 /* the kind of operations supported; you could easily imagine
67  * that instead of passing a tag describing the work to be performed,
68  * a function pointer is passed instead. Maybe later.
69  */
70 #define WORKER_READ        1
71 #define WORKER_WRITE       2
72 #define WORKER_DELAY       4
73 #define WORKER_FOR_SOCKET  8
74 #define WORKER_DO_PROC    16
75
76 /*
77  * Starting up and shutting down. 
78  */ 
79 extern BOOL StartIOManager     ( void );
80 extern void ShutdownIOManager  ( void );
81
82 /*
83  * Adding I/O and delay requests. With each request a
84  * completion routine is supplied, which the worker thread
85  * will invoke upon completion.
86  */
87 extern int AddDelayRequest ( unsigned int   msecs,
88                              CompletionProc onCompletion);
89
90 extern int AddIORequest ( int            fd,
91                           BOOL           forWriting,
92                           BOOL           isSocket,
93                           int            len,
94                           char*          buffer,
95                           CompletionProc onCompletion);
96
97 extern int AddProcRequest ( void*          proc,
98                             void*          data,
99                             CompletionProc onCompletion);
100
101 #endif /* __IOMANAGER_H__ */