- Remove winmm hack in dplay code
[wine] / dlls / dplayx / dplayx_queue.h
1 /* A queue definition based on sys/queue.h TAILQ definitions
2  * 
3  * Blame any implementation mistakes on Peter Hunnisett
4  * <hunnise@nortelnetworks.com>
5  */
6
7 #ifndef __WINE_DPLAYX_QUEUE_H
8 #define __WINE_DPLAYX_QUEUE_H
9
10 #include "winbase.h"
11
12 #define DPQ_INSERT(a,b,c) DPQ_INSERT_IN_TAIL(a,b,c)
13
14 /*
15  * Tail queue definitions.
16  */
17 #define DPQ_HEAD(type)                                           \
18 struct {                                                         \
19         struct type *lpQHFirst; /* first element */              \
20         struct type **lpQHLast; /* addr of last next element */  \
21 }
22
23 #define DPQ_ENTRY(type)                                               \
24 struct {                                                              \
25         struct type *lpQNext;  /* next element */                     \
26         struct type **lpQPrev; /* address of previous next element */ \
27 }
28
29 /*
30  * Tail queue functions.
31  */
32 #define DPQ_INIT(head)                       \
33 do{                                          \
34         (head).lpQHFirst = NULL;             \
35         (head).lpQHLast = &(head).lpQHFirst; \
36 } while(0)
37
38 /* Front of the queue */
39 #define DPQ_FIRST( head ) ( (head).lpQHFirst )
40
41 /* Check if the queue has any elements */
42 #define DPQ_IS_EMPTY( head ) ( DPQ_FIRST(head) == NULL ) 
43
44 /* Next entry -- FIXME: Convert everything over to this macro ... */
45 #define DPQ_NEXT( elem ) (elem).lpQNext
46
47 #define DPQ_IS_ENDOFLIST( elem ) \
48     ( DPQ_NEXT(elem) == NULL )
49
50 /* Insert element at end of queue */
51 #define DPQ_INSERT_IN_TAIL(head, elm, field)     \
52 do {                                             \
53         (elm)->field.lpQNext = NULL;             \
54         (elm)->field.lpQPrev = (head).lpQHLast;  \
55         *(head).lpQHLast = (elm);                \
56         (head).lpQHLast = &(elm)->field.lpQNext; \
57 } while(0)
58
59 /* Remove element from the queue */
60 #define DPQ_REMOVE(head, elm, field)                    \
61 do {                                                    \
62         if (((elm)->field.lpQNext) != NULL)             \
63                 (elm)->field.lpQNext->field.lpQPrev =   \
64                     (elm)->field.lpQPrev;               \
65         else                                            \
66                 (head).lpQHLast = (elm)->field.lpQPrev; \
67         *(elm)->field.lpQPrev = (elm)->field.lpQNext;   \
68 } while(0)
69
70 /* head - pointer to DPQ_HEAD struct
71  * elm  - how to find the next element
72  * field - to be concatenated to rc to compare with fieldToCompare
73  * fieldToCompare - The value that we're comparing against
74  * fieldCompareOperator - The logical operator to compare field and
75  *                        fieldToCompare. 
76  * rc - Variable to put the return code. Same type as (head).lpQHFirst
77  */
78 #define DPQ_FIND_ENTRY( head, elm, field, fieldCompareOperator, fieldToCompare, rc )\
79 do {                                                           \
80   (rc) = DPQ_FIRST(head); /* NULL head? */                     \
81                                                                \
82   while( rc )                                                  \
83   {                                                            \
84       /* What we're searching for? */                          \
85       if( (rc)->field fieldCompareOperator (fieldToCompare) )  \
86       {                                                        \
87         break; /* rc == correct element */                     \
88       }                                                        \
89                                                                \
90       /* End of list check */                                  \
91       if( ( (rc) = (rc)->elm.lpQNext ) == (head).lpQHFirst )   \
92       {                                                        \
93         rc = NULL;                                             \
94         break;                                                 \
95       }                                                        \
96   }                                                            \
97 } while(0)
98
99 /* head - pointer to DPQ_HEAD struct
100  * elm  - how to find the next element
101  * field - to be concatenated to rc to compare with fieldToCompare
102  * fieldToCompare - The value that we're comparing against
103  * compare_cb - Callback to invoke to determine if comparision should continue.
104  *              Callback must be defined with DPQ_DECL_COMPARECB. 
105  * rc - Variable to put the return code. Same type as (head).lpQHFirst
106  */
107 #define DPQ_FIND_ENTRY_CB( head, elm, field, compare_cb, fieldToCompare, rc )\
108 do {                                                           \
109   (rc) = DPQ_FIRST(head); /* NULL head? */                     \
110                                                                \
111   while( rc )                                                  \
112   {                                                            \
113       /* What we're searching for? */                          \
114       if( compare_cb( &((rc)->field), &(fieldToCompare) ) )    \
115       {                                                        \
116         break; /* no more */                                   \
117       }                                                        \
118                                                                \
119       /* End of list check */                                  \
120       if( ( (rc) = (rc)->elm.lpQNext ) == (head).lpQHFirst )   \
121       {                                                        \
122         rc = NULL;                                             \
123         break;                                                 \
124       }                                                        \
125   }                                                            \
126 } while(0)
127
128 /* How to define the method to be passed to DPQ_DELETEQ */
129 #define DPQ_DECL_COMPARECB( name, type ) BOOL name( const type* elem1, const type* elem2 )
130
131
132 /* head - pointer to DPQ_HEAD struct
133  * elm  - how to find the next element
134  * field - to be concatenated to rc to compare with fieldToEqual
135  * fieldToCompare - The value that we're comparing against
136  * fieldCompareOperator - The logical operator to compare field and
137  *                        fieldToCompare.
138  * rc - Variable to put the return code. Same type as (head).lpQHFirst
139  */
140 #define DPQ_REMOVE_ENTRY( head, elm, field, fieldCompareOperator, fieldToCompare, rc )\
141 do {                                                           \
142   DPQ_FIND_ENTRY( head, elm, field, fieldCompareOperator, fieldToCompare, rc );\
143                                                                \
144   /* Was the element found? */                                 \
145   if( rc )                                                     \
146   {                                                            \
147     DPQ_REMOVE( head, rc, elm );                               \
148   }                                                            \
149 } while(0)
150
151 /* head - pointer to DPQ_HEAD struct
152  * elm  - how to find the next element
153  * field - to be concatenated to rc to compare with fieldToCompare
154  * fieldToCompare - The value that we're comparing against
155  * compare_cb - Callback to invoke to determine if comparision should continue.
156  *              Callback must be defined with DPQ_DECL_COMPARECB.
157  * rc - Variable to put the return code. Same type as (head).lpQHFirst
158  */
159 #define DPQ_REMOVE_ENTRY_CB( head, elm, field, compare_cb, fieldToCompare, rc )\
160 do {                                                           \
161   DPQ_FIND_ENTRY_CB( head, elm, field, compare_cb, fieldToCompare, rc );\
162                                                                \
163   /* Was the element found? */                                 \
164   if( rc )                                                     \
165   {                                                            \
166     DPQ_REMOVE( head, rc, elm );                               \
167   }                                                            \
168 } while(0)
169
170
171 /* Delete the entire queue 
172  * head - pointer to the head of the queue
173  * field - field to access the next elements of the queue
174  * type - type of the pointer to the element element
175  * df - a delete function to be called. Declared with DPQ_DECL_DELETECB.
176  */
177 #define DPQ_DELETEQ( head, field, type, df )     \
178 do                                               \
179 {                                                \
180   while( !DPQ_IS_EMPTY(head) )                   \
181   {                                              \
182     type holder = DPQ_FIRST(head);               \
183     DPQ_REMOVE( head, holder, field );           \
184     df( holder );                                \
185   }                                              \
186 } while(0)
187
188 /* How to define the method to be passed to DPQ_DELETEQ */
189 #define DPQ_DECL_DELETECB( name, type ) void name( type elem )
190
191 /* Prototype of a method which just performs a HeapFree on the elem */
192 DPQ_DECL_DELETECB( cbDeleteElemFromHeap, LPVOID );
193
194 #endif /* __WINE_DPLAYX_QUEUE_H */