RTS tidyup sweep, first phase
[ghc-hetmet.git] / rts / win32 / WorkQueue.h
1 /* WorkQueue.h
2  *
3  * A fixed-size queue; MT-friendly.
4  * 
5  * (c) sof, 2002-2003
6  *
7  */
8
9 #ifndef WIN32_WORKQUEUE_H
10 #define WIN32_WORKQUEUE_H
11 #include <windows.h>
12
13 /* This is a fixed-size queue. */
14 #define WORKQUEUE_SIZE 16
15
16 typedef HANDLE           Semaphore;
17 typedef CRITICAL_SECTION CritSection;
18
19 typedef struct WorkQueue {
20     /* the master lock, need to be grabbed prior to
21        using any of the other elements of the struct. */
22   CritSection   queueLock;
23   /* consumers/workers block waiting for 'workAvailable' */
24   Semaphore     workAvailable;
25   Semaphore     roomAvailable;
26   int           head;
27   int           tail;
28   void**        items[WORKQUEUE_SIZE];
29 } WorkQueue;
30
31 extern WorkQueue* NewWorkQueue       ( void );
32 extern void       FreeWorkQueue      ( WorkQueue* pq );
33 extern HANDLE     GetWorkQueueHandle ( WorkQueue* pq );
34 extern BOOL       GetWork            ( WorkQueue* pq, void** ppw );
35 extern BOOL       FetchWork          ( WorkQueue* pq, void** ppw );
36 extern int        SubmitWork         ( WorkQueue* pq, void*   pw );
37
38 #endif /* WIN32_WORKQUEUE_H */