3 * Non-blocking / asynchronous I/O for Win32.
7 #ifndef __IOMANAGER_H__
8 #define __IOMANAGER_H__
9 /* On the yucky side..suppress -Wmissing-declarations warnings when
10 * including <windows.h>
12 extern void* GetCurrentFiber ( void );
13 extern void* GetFiberData ( void );
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.
25 The IOManager is intended used with the GHC RTS to
26 implement non-blocking I/O in Concurrent Haskell.
30 * Our WorkQueue holds WorkItems, encoding IO and
34 typedef void (*CompletionProc)(unsigned int requestID,
41 * Asynchronous procedure calls executed by a worker thread
42 * take a generic state argument pointer and return an int by
45 typedef int (*DoProcProc)(void *param);
47 typedef union workData {
62 typedef struct WorkItem {
63 unsigned int workKind;
65 unsigned int requestID;
66 CompletionProc onCompletion;
67 unsigned int abandonOp;
68 struct WorkItem *link;
71 extern CompletionProc onComplete;
73 /* the kind of operations supported; you could easily imagine
74 * that instead of passing a tag describing the work to be performed,
75 * a function pointer is passed instead. Maybe later.
78 #define WORKER_WRITE 2
79 #define WORKER_DELAY 4
80 #define WORKER_FOR_SOCKET 8
81 #define WORKER_DO_PROC 16
84 * Starting up and shutting down.
86 extern BOOL StartIOManager ( void );
87 extern void ShutdownIOManager ( void );
90 * Adding I/O and delay requests. With each request a
91 * completion routine is supplied, which the worker thread
92 * will invoke upon completion.
94 extern int AddDelayRequest ( unsigned int msecs,
95 CompletionProc onCompletion);
97 extern int AddIORequest ( int fd,
102 CompletionProc onCompletion);
104 extern int AddProcRequest ( void* proc,
106 CompletionProc onCompletion);
108 extern void abandonWorkRequest ( int reqID );
110 #endif /* __IOMANAGER_H__ */