3 * Non-blocking / asynchronous I/O for Win32.
8 #ifndef WIN32_IOMANAGER_H
9 #define WIN32_IOMANAGER_H
14 The IOManager subsystem provides a non-blocking view
15 of I/O operations. It lets one (or more) OS thread(s)
16 issue multiple I/O requests, which the IOManager then
17 handles independently of/concurrent to the thread(s)
18 that issued the request. Upon completion, the issuing
19 thread can inspect the result of the I/O operation &
20 take appropriate action.
22 The IOManager is intended used with the GHC RTS to
23 implement non-blocking I/O in Concurrent Haskell.
27 * Our WorkQueue holds WorkItems, encoding IO and
31 typedef void (*CompletionProc)(unsigned int requestID,
38 * Asynchronous procedure calls executed by a worker thread
39 * take a generic state argument pointer and return an int by
42 typedef int (*DoProcProc)(void *param);
44 typedef union workData {
59 typedef struct WorkItem {
60 unsigned int workKind;
62 unsigned int requestID;
63 CompletionProc onCompletion;
64 unsigned int abandonOp;
65 struct WorkItem *link;
68 extern CompletionProc onComplete;
70 /* the kind of operations supported; you could easily imagine
71 * that instead of passing a tag describing the work to be performed,
72 * a function pointer is passed instead. Maybe later.
75 #define WORKER_WRITE 2
76 #define WORKER_DELAY 4
77 #define WORKER_FOR_SOCKET 8
78 #define WORKER_DO_PROC 16
81 * Starting up and shutting down.
83 extern BOOL StartIOManager ( void );
84 extern void ShutdownIOManager ( rtsBool wait_threads );
87 * Adding I/O and delay requests. With each request a
88 * completion routine is supplied, which the worker thread
89 * will invoke upon completion.
91 extern int AddDelayRequest ( unsigned int msecs,
92 CompletionProc onCompletion);
94 extern int AddIORequest ( int fd,
99 CompletionProc onCompletion);
101 extern int AddProcRequest ( void* proc,
103 CompletionProc onCompletion);
105 extern void abandonWorkRequest ( int reqID );
107 #endif /* WIN32_IOMANAGER_H */