summaryrefslogtreecommitdiff
path: root/rts/win32/WorkQueue.h
blob: eb0b601df3e449bf10bb44306dcdd5c0030565d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/* WorkQueue.h
 *
 * A fixed-size queue; MT-friendly.
 *
 * (c) sof, 2002-2003
 *
 */

#ifndef WIN32_WORKQUEUE_H
#define WIN32_WORKQUEUE_H
#include <windows.h>

/* This is a fixed-size queue. */
#define WORKQUEUE_SIZE 16

typedef HANDLE           Semaphore;
typedef CRITICAL_SECTION CritSection;

typedef struct WorkQueue {
    /* the master lock, need to be grabbed prior to
       using any of the other elements of the struct. */
  CritSection   queueLock;
  /* consumers/workers block waiting for 'workAvailable' */
  Semaphore     workAvailable;
  Semaphore     roomAvailable;
  int           head;
  int           tail;
  void**        items[WORKQUEUE_SIZE];
} WorkQueue;

extern WorkQueue* NewWorkQueue       ( void );
extern void       FreeWorkQueue      ( WorkQueue* pq );
extern HANDLE     GetWorkQueueHandle ( WorkQueue* pq );
extern BOOL       GetWork            ( WorkQueue* pq, void** ppw );
extern BOOL       FetchWork          ( WorkQueue* pq, void** ppw );
extern int        SubmitWork         ( WorkQueue* pq, void*   pw );

#endif /* WIN32_WORKQUEUE_H */