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
25 #define DPQ_INSERT(a,b,c) DPQ_INSERT_IN_TAIL(a,b,c)
28 * Tail queue definitions.
30 #define DPQ_HEAD(type) \
32 struct type *lpQHFirst; /* first element */ \
33 struct type **lpQHLast; /* addr of last next element */ \
36 #define DPQ_ENTRY(type) \
38 struct type *lpQNext; /* next element */ \
39 struct type **lpQPrev; /* address of previous next element */ \
43 * Tail queue functions.
45 #define DPQ_INIT(head) \
47 (head).lpQHFirst = NULL; \
48 (head).lpQHLast = &(head).lpQHFirst; \
51 /* Front of the queue */
52 #define DPQ_FIRST( head ) ( (head).lpQHFirst )
54 /* Check if the queue has any elements */
55 #define DPQ_IS_EMPTY( head ) ( DPQ_FIRST(head) == NULL )
57 /* Next entry -- FIXME: Convert everything over to this macro ... */
58 #define DPQ_NEXT( elem ) (elem).lpQNext
60 #define DPQ_IS_ENDOFLIST( elem ) \
61 ( DPQ_NEXT(elem) == NULL )
63 /* Insert element at end of queue */
64 #define DPQ_INSERT_IN_TAIL(head, elm, field) \
66 (elm)->field.lpQNext = NULL; \
67 (elm)->field.lpQPrev = (head).lpQHLast; \
68 *(head).lpQHLast = (elm); \
69 (head).lpQHLast = &(elm)->field.lpQNext; \
72 /* Remove element from the queue */
73 #define DPQ_REMOVE(head, elm, field) \
75 if (((elm)->field.lpQNext) != NULL) \
76 (elm)->field.lpQNext->field.lpQPrev = \
77 (elm)->field.lpQPrev; \
79 (head).lpQHLast = (elm)->field.lpQPrev; \
80 *(elm)->field.lpQPrev = (elm)->field.lpQNext; \
83 /* head - pointer to DPQ_HEAD struct
84 * elm - how to find the next element
85 * field - to be concatenated to rc to compare with fieldToCompare
86 * fieldToCompare - The value that we're comparing against
87 * fieldCompareOperator - The logical operator to compare field and
89 * rc - Variable to put the return code. Same type as (head).lpQHFirst
91 #define DPQ_FIND_ENTRY( head, elm, field, fieldCompareOperator, fieldToCompare, rc )\
93 (rc) = DPQ_FIRST(head); /* NULL head? */ \
97 /* What we're searching for? */ \
98 if( (rc)->field fieldCompareOperator (fieldToCompare) ) \
100 break; /* rc == correct element */ \
103 /* End of list check */ \
104 if( ( (rc) = (rc)->elm.lpQNext ) == (head).lpQHFirst ) \
112 /* head - pointer to DPQ_HEAD struct
113 * elm - how to find the next element
114 * field - to be concatenated to rc to compare with fieldToCompare
115 * fieldToCompare - The value that we're comparing against
116 * compare_cb - Callback to invoke to determine if comparision should continue.
117 * Callback must be defined with DPQ_DECL_COMPARECB.
118 * rc - Variable to put the return code. Same type as (head).lpQHFirst
120 #define DPQ_FIND_ENTRY_CB( head, elm, field, compare_cb, fieldToCompare, rc )\
122 (rc) = DPQ_FIRST(head); /* NULL head? */ \
126 /* What we're searching for? */ \
127 if( compare_cb( &((rc)->field), &(fieldToCompare) ) ) \
129 break; /* no more */ \
132 /* End of list check */ \
133 if( ( (rc) = (rc)->elm.lpQNext ) == (head).lpQHFirst ) \
141 /* How to define the method to be passed to DPQ_DELETEQ */
142 #define DPQ_DECL_COMPARECB( name, type ) BOOL name( const type* elem1, const type* elem2 )
145 /* head - pointer to DPQ_HEAD struct
146 * elm - how to find the next element
147 * field - to be concatenated to rc to compare with fieldToEqual
148 * fieldToCompare - The value that we're comparing against
149 * fieldCompareOperator - The logical operator to compare field and
151 * rc - Variable to put the return code. Same type as (head).lpQHFirst
153 #define DPQ_REMOVE_ENTRY( head, elm, field, fieldCompareOperator, fieldToCompare, rc )\
155 DPQ_FIND_ENTRY( head, elm, field, fieldCompareOperator, fieldToCompare, rc );\
157 /* Was the element found? */ \
160 DPQ_REMOVE( head, rc, elm ); \
164 /* head - pointer to DPQ_HEAD struct
165 * elm - how to find the next element
166 * field - to be concatenated to rc to compare with fieldToCompare
167 * fieldToCompare - The value that we're comparing against
168 * compare_cb - Callback to invoke to determine if comparision should continue.
169 * Callback must be defined with DPQ_DECL_COMPARECB.
170 * rc - Variable to put the return code. Same type as (head).lpQHFirst
172 #define DPQ_REMOVE_ENTRY_CB( head, elm, field, compare_cb, fieldToCompare, rc )\
174 DPQ_FIND_ENTRY_CB( head, elm, field, compare_cb, fieldToCompare, rc );\
176 /* Was the element found? */ \
179 DPQ_REMOVE( head, rc, elm ); \
184 /* Delete the entire queue
185 * head - pointer to the head of the queue
186 * field - field to access the next elements of the queue
187 * type - type of the pointer to the element element
188 * df - a delete function to be called. Declared with DPQ_DECL_DELETECB.
190 #define DPQ_DELETEQ( head, field, type, df ) \
193 while( !DPQ_IS_EMPTY(head) ) \
195 type holder = DPQ_FIRST(head); \
196 DPQ_REMOVE( head, holder, field ); \
201 /* How to define the method to be passed to DPQ_DELETEQ */
202 #define DPQ_DECL_DELETECB( name, type ) void name( type elem )
204 /* Prototype of a method which just performs a HeapFree on the elem */
205 DPQ_DECL_DELETECB( cbDeleteElemFromHeap, LPVOID );
207 #endif /* __WINE_DPLAYX_QUEUE_H */