1 /* A queue definition based on sys/queue.h TAILQ definitions
3 * Blame any implementation mistakes on Peter Hunnisett
4 * <hunnise@nortelnetworks.com>
7 #ifndef __WINE_DPLAYX_QUEUE_H
8 #define __WINE_DPLAYX_QUEUE_H
12 #define DPQ_INSERT(a,b,c) DPQ_INSERT_IN_TAIL(a,b,c)
15 * Tail queue definitions.
17 #define DPQ_HEAD(type) \
19 struct type *lpQHFirst; /* first element */ \
20 struct type **lpQHLast; /* addr of last next element */ \
23 #define DPQ_ENTRY(type) \
25 struct type *lpQNext; /* next element */ \
26 struct type **lpQPrev; /* address of previous next element */ \
30 * Tail queue functions.
32 #define DPQ_INIT(head) \
34 (head).lpQHFirst = NULL; \
35 (head).lpQHLast = &(head).lpQHFirst; \
38 /* Front of the queue */
39 #define DPQ_FIRST( head ) ( (head).lpQHFirst )
41 /* Check if the queue has any elements */
42 #define DPQ_IS_EMPTY( head ) ( DPQ_FIRST(head) == NULL )
44 /* Next entry -- FIXME: Convert everything over to this macro ... */
45 #define DPQ_NEXT( elem ) (elem).lpQNext
47 #define DPQ_IS_ENDOFLIST( elem ) \
48 ( DPQ_NEXT(elem) == NULL )
50 /* Insert element at end of queue */
51 #define DPQ_INSERT_IN_TAIL(head, elm, field) \
53 (elm)->field.lpQNext = NULL; \
54 (elm)->field.lpQPrev = (head).lpQHLast; \
55 *(head).lpQHLast = (elm); \
56 (head).lpQHLast = &(elm)->field.lpQNext; \
59 /* Remove element from the queue */
60 #define DPQ_REMOVE(head, elm, field) \
62 if (((elm)->field.lpQNext) != NULL) \
63 (elm)->field.lpQNext->field.lpQPrev = \
64 (elm)->field.lpQPrev; \
66 (head).lpQHLast = (elm)->field.lpQPrev; \
67 *(elm)->field.lpQPrev = (elm)->field.lpQNext; \
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
76 * rc - Variable to put the return code. Same type as (head).lpQHFirst
78 #define DPQ_FIND_ENTRY( head, elm, field, fieldCompareOperator, fieldToCompare, rc )\
80 (rc) = DPQ_FIRST(head); /* NULL head? */ \
84 /* What we're searching for? */ \
85 if( (rc)->field fieldCompareOperator (fieldToCompare) ) \
87 break; /* rc == correct element */ \
90 /* End of list check */ \
91 if( ( (rc) = (rc)->elm.lpQNext ) == (head).lpQHFirst ) \
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
107 #define DPQ_FIND_ENTRY_CB( head, elm, field, compare_cb, fieldToCompare, rc )\
109 (rc) = DPQ_FIRST(head); /* NULL head? */ \
113 /* What we're searching for? */ \
114 if( compare_cb( &((rc)->field), &(fieldToCompare) ) ) \
116 break; /* no more */ \
119 /* End of list check */ \
120 if( ( (rc) = (rc)->elm.lpQNext ) == (head).lpQHFirst ) \
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 )
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
138 * rc - Variable to put the return code. Same type as (head).lpQHFirst
140 #define DPQ_REMOVE_ENTRY( head, elm, field, fieldCompareOperator, fieldToCompare, rc )\
142 DPQ_FIND_ENTRY( head, elm, field, fieldCompareOperator, fieldToCompare, rc );\
144 /* Was the element found? */ \
147 DPQ_REMOVE( head, rc, elm ); \
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
159 #define DPQ_REMOVE_ENTRY_CB( head, elm, field, compare_cb, fieldToCompare, rc )\
161 DPQ_FIND_ENTRY_CB( head, elm, field, compare_cb, fieldToCompare, rc );\
163 /* Was the element found? */ \
166 DPQ_REMOVE( head, rc, elm ); \
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.
177 #define DPQ_DELETEQ( head, field, type, df ) \
180 while( !DPQ_IS_EMPTY(head) ) \
182 type holder = DPQ_FIRST(head); \
183 DPQ_REMOVE( head, holder, field ); \
188 /* How to define the method to be passed to DPQ_DELETEQ */
189 #define DPQ_DECL_DELETECB( name, type ) void name( type elem )
191 /* Prototype of a method which just performs a HeapFree on the elem */
192 DPQ_DECL_DELETECB( cbDeleteElemFromHeap, LPVOID );
194 #endif /* __WINE_DPLAYX_QUEUE_H */