3 * Non-blocking / asynchronous I/O for Win32.
7 #ifndef __IOMANAGER_H__
8 #define __IOMANAGER_H__
13 The IOManager subsystem provides a non-blocking view
14 of I/O operations. It lets one (or more) OS thread(s)
15 issue multiple I/O requests, which the IOManager then
16 handles independently of/concurrent to the thread(s)
17 that issued the request. Upon completion, the issuing
18 thread can inspect the result of the I/O operation &
19 take appropriate action.
21 The IOManager is intended used with the GHC RTS to
22 implement non-blocking I/O in Concurrent Haskell.
26 * Our WorkQueue holds WorkItems, encoding IO and
30 typedef void (*CompletionProc)(unsigned int requestID,
37 * Asynchronous procedure calls executed by a worker thread
38 * take a generic state argument pointer and return an int by
41 typedef int (*DoProcProc)(void *param);
43 typedef union workData {
58 typedef struct WorkItem {
59 unsigned int workKind;
61 unsigned int requestID;
62 CompletionProc onCompletion;
63 unsigned int abandonOp;
64 struct WorkItem *link;
67 extern CompletionProc onComplete;
69 /* the kind of operations supported; you could easily imagine
70 * that instead of passing a tag describing the work to be performed,
71 * a function pointer is passed instead. Maybe later.
74 #define WORKER_WRITE 2
75 #define WORKER_DELAY 4
76 #define WORKER_FOR_SOCKET 8
77 #define WORKER_DO_PROC 16
80 * Starting up and shutting down.
82 extern BOOL StartIOManager ( void );
83 extern void ShutdownIOManager ( rtsBool wait_threads );
86 * Adding I/O and delay requests. With each request a
87 * completion routine is supplied, which the worker thread
88 * will invoke upon completion.
90 extern int AddDelayRequest ( unsigned int msecs,
91 CompletionProc onCompletion);
93 extern int AddIORequest ( int fd,
98 CompletionProc onCompletion);
100 extern int AddProcRequest ( void* proc,
102 CompletionProc onCompletion);
104 extern void abandonWorkRequest ( int reqID );
106 #endif /* __IOMANAGER_H__ */