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