1 /* A queue definition based on sys/queue.h TAILQ definitions
3 * Copyright 2000 Peter Hunnisett
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #ifndef __WINE_DPLAYX_QUEUE_H
21 #define __WINE_DPLAYX_QUEUE_H
28 #define DPQ_INSERT(a,b,c) DPQ_INSERT_IN_TAIL(a,b,c)
31 * Tail queue definitions.
33 #define DPQ_HEAD(type) \
35 struct type *lpQHFirst; /* first element */ \
36 struct type **lpQHLast; /* addr of last next element */ \
39 #define DPQ_ENTRY(type) \
41 struct type *lpQNext; /* next element */ \
42 struct type **lpQPrev; /* address of previous next element */ \
46 * Tail queue functions.
48 #define DPQ_INIT(head) \
50 (head).lpQHFirst = NULL; \
51 (head).lpQHLast = &(head).lpQHFirst; \
54 /* Front of the queue */
55 #define DPQ_FIRST( head ) ( (head).lpQHFirst )
57 /* Check if the queue has any elements */
58 #define DPQ_IS_EMPTY( head ) ( DPQ_FIRST(head) == NULL )
60 /* Next entry -- FIXME: Convert everything over to this macro ... */
61 #define DPQ_NEXT( elem ) (elem).lpQNext
63 #define DPQ_IS_ENDOFLIST( elem ) \
64 ( DPQ_NEXT(elem) == NULL )
66 /* Insert element at end of queue */
67 #define DPQ_INSERT_IN_TAIL(head, elm, field) \
69 (elm)->field.lpQNext = NULL; \
70 (elm)->field.lpQPrev = (head).lpQHLast; \
71 *(head).lpQHLast = (elm); \
72 (head).lpQHLast = &(elm)->field.lpQNext; \
75 /* Remove element from the queue */
76 #define DPQ_REMOVE(head, elm, field) \
78 if (((elm)->field.lpQNext) != NULL) \
79 (elm)->field.lpQNext->field.lpQPrev = \
80 (elm)->field.lpQPrev; \
82 (head).lpQHLast = (elm)->field.lpQPrev; \
83 *(elm)->field.lpQPrev = (elm)->field.lpQNext; \
86 /* head - pointer to DPQ_HEAD struct
87 * elm - how to find the next element
88 * field - to be concatenated to rc to compare with fieldToCompare
89 * fieldToCompare - The value that we're comparing against
90 * fieldCompareOperator - The logical operator to compare field and
92 * rc - Variable to put the return code. Same type as (head).lpQHFirst
94 #define DPQ_FIND_ENTRY( head, elm, field, fieldCompareOperator, fieldToCompare, rc )\
96 (rc) = DPQ_FIRST(head); /* NULL head? */ \
100 /* What we're searching for? */ \
101 if( (rc)->field fieldCompareOperator (fieldToCompare) ) \
103 break; /* rc == correct element */ \
106 /* End of list check */ \
107 if( ( (rc) = (rc)->elm.lpQNext ) == (head).lpQHFirst ) \
115 /* head - pointer to DPQ_HEAD struct
116 * elm - how to find the next element
117 * field - to be concatenated to rc to compare with fieldToCompare
118 * fieldToCompare - The value that we're comparing against
119 * compare_cb - Callback to invoke to determine if comparision should continue.
120 * Callback must be defined with DPQ_DECL_COMPARECB.
121 * rc - Variable to put the return code. Same type as (head).lpQHFirst
123 #define DPQ_FIND_ENTRY_CB( head, elm, field, compare_cb, fieldToCompare, rc )\
125 (rc) = DPQ_FIRST(head); /* NULL head? */ \
129 /* What we're searching for? */ \
130 if( compare_cb( &((rc)->field), &(fieldToCompare) ) ) \
132 break; /* no more */ \
135 /* End of list check */ \
136 if( ( (rc) = (rc)->elm.lpQNext ) == (head).lpQHFirst ) \
144 /* How to define the method to be passed to DPQ_DELETEQ */
145 #define DPQ_DECL_COMPARECB( name, type ) BOOL name( const type* elem1, const type* elem2 )
148 /* head - pointer to DPQ_HEAD struct
149 * elm - how to find the next element
150 * field - to be concatenated to rc to compare with fieldToEqual
151 * fieldToCompare - The value that we're comparing against
152 * fieldCompareOperator - The logical operator to compare field and
154 * rc - Variable to put the return code. Same type as (head).lpQHFirst
156 #define DPQ_REMOVE_ENTRY( head, elm, field, fieldCompareOperator, fieldToCompare, rc )\
158 DPQ_FIND_ENTRY( head, elm, field, fieldCompareOperator, fieldToCompare, rc );\
160 /* Was the element found? */ \
163 DPQ_REMOVE( head, rc, elm ); \
167 /* head - pointer to DPQ_HEAD struct
168 * elm - how to find the next element
169 * field - to be concatenated to rc to compare with fieldToCompare
170 * fieldToCompare - The value that we're comparing against
171 * compare_cb - Callback to invoke to determine if comparision should continue.
172 * Callback must be defined with DPQ_DECL_COMPARECB.
173 * rc - Variable to put the return code. Same type as (head).lpQHFirst
175 #define DPQ_REMOVE_ENTRY_CB( head, elm, field, compare_cb, fieldToCompare, rc )\
177 DPQ_FIND_ENTRY_CB( head, elm, field, compare_cb, fieldToCompare, rc );\
179 /* Was the element found? */ \
182 DPQ_REMOVE( head, rc, elm ); \
187 /* Delete the entire queue
188 * head - pointer to the head of the queue
189 * field - field to access the next elements of the queue
190 * type - type of the pointer to the element element
191 * df - a delete function to be called. Declared with DPQ_DECL_DELETECB.
193 #define DPQ_DELETEQ( head, field, type, df ) \
196 while( !DPQ_IS_EMPTY(head) ) \
198 type holder = DPQ_FIRST(head); \
199 DPQ_REMOVE( head, holder, field ); \
204 /* How to define the method to be passed to DPQ_DELETEQ */
205 #define DPQ_DECL_DELETECB( name, type ) void name( type elem )
207 /* Prototype of a method which just performs a HeapFree on the elem */
208 DPQ_DECL_DELETECB( cbDeleteElemFromHeap, LPVOID );
210 #endif /* __WINE_DPLAYX_QUEUE_H */