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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 * o Linked list implementation for dplay/dplobby. Based off of the BSD
21 * version found in <sys/queue.h>
22 * o Port it to <wine/list.h> ?
26 #ifndef __WINE_DPLAYX_QUEUE_H
27 #define __WINE_DPLAYX_QUEUE_H
29 #define DPQ_INSERT(a,b,c) DPQ_INSERT_IN_TAIL(a,b,c)
32 * Tail queue definitions.
34 #define DPQ_HEAD(type) \
36 struct type *lpQHFirst; /* first element */ \
37 struct type **lpQHLast; /* addr of last next element */ \
40 #define DPQ_ENTRY(type) \
42 struct type *lpQNext; /* next element */ \
43 struct type **lpQPrev; /* address of previous next element */ \
47 * Tail queue functions.
49 #define DPQ_INIT(head) \
51 (head).lpQHFirst = NULL; \
52 (head).lpQHLast = &(head).lpQHFirst; \
55 /* Front of the queue */
56 #define DPQ_FIRST( head ) ( (head).lpQHFirst )
58 /* Check if the queue has any elements */
59 #define DPQ_IS_EMPTY( head ) ( DPQ_FIRST(head) == NULL )
61 /* Next entry -- FIXME: Convert everything over to this macro ... */
62 #define DPQ_NEXT( elem ) (elem).lpQNext
64 #define DPQ_IS_ENDOFLIST( elem ) \
65 ( DPQ_NEXT(elem) == NULL )
67 /* Insert element at end of queue */
68 #define DPQ_INSERT_IN_TAIL(head, elm, field) \
70 (elm)->field.lpQNext = NULL; \
71 (elm)->field.lpQPrev = (head).lpQHLast; \
72 *(head).lpQHLast = (elm); \
73 (head).lpQHLast = &(elm)->field.lpQNext; \
76 /* Remove element from the queue */
77 #define DPQ_REMOVE(head, elm, field) \
79 if (((elm)->field.lpQNext) != NULL) \
80 (elm)->field.lpQNext->field.lpQPrev = \
81 (elm)->field.lpQPrev; \
83 (head).lpQHLast = (elm)->field.lpQPrev; \
84 *(elm)->field.lpQPrev = (elm)->field.lpQNext; \
87 /* head - pointer to DPQ_HEAD struct
88 * elm - how to find the next element
89 * field - to be concatenated to rc to compare with fieldToCompare
90 * fieldToCompare - The value that we're comparing against
91 * fieldCompareOperator - The logical operator to compare field and
93 * rc - Variable to put the return code. Same type as (head).lpQHFirst
95 #define DPQ_FIND_ENTRY( head, elm, field, fieldCompareOperator, fieldToCompare, rc )\
97 (rc) = DPQ_FIRST(head); /* NULL head? */ \
101 /* What we're searching for? */ \
102 if( (rc)->field fieldCompareOperator (fieldToCompare) ) \
104 break; /* rc == correct element */ \
107 /* End of list check */ \
108 if( ( (rc) = (rc)->elm.lpQNext ) == (head).lpQHFirst ) \
116 /* head - pointer to DPQ_HEAD struct
117 * elm - how to find the next element
118 * field - to be concatenated to rc to compare with fieldToCompare
119 * fieldToCompare - The value that we're comparing against
120 * compare_cb - Callback to invoke to determine if comparison should continue.
121 * Callback must be defined with DPQ_DECL_COMPARECB.
122 * rc - Variable to put the return code. Same type as (head).lpQHFirst
124 #define DPQ_FIND_ENTRY_CB( head, elm, field, compare_cb, fieldToCompare, rc )\
126 (rc) = DPQ_FIRST(head); /* NULL head? */ \
130 /* What we're searching for? */ \
131 if( compare_cb( &((rc)->field), &(fieldToCompare) ) ) \
133 break; /* no more */ \
136 /* End of list check */ \
137 if( ( (rc) = (rc)->elm.lpQNext ) == (head).lpQHFirst ) \
145 /* How to define the method to be passed to DPQ_DELETEQ */
146 #define DPQ_DECL_COMPARECB( name, type ) BOOL name( const type* elem1, const type* elem2 )
149 /* head - pointer to DPQ_HEAD struct
150 * elm - how to find the next element
151 * field - to be concatenated to rc to compare with fieldToEqual
152 * fieldToCompare - The value that we're comparing against
153 * fieldCompareOperator - The logical operator to compare field and
155 * rc - Variable to put the return code. Same type as (head).lpQHFirst
157 #define DPQ_REMOVE_ENTRY( head, elm, field, fieldCompareOperator, fieldToCompare, rc )\
159 DPQ_FIND_ENTRY( head, elm, field, fieldCompareOperator, fieldToCompare, rc );\
161 /* Was the element found? */ \
164 DPQ_REMOVE( head, rc, elm ); \
168 /* head - pointer to DPQ_HEAD struct
169 * elm - how to find the next element
170 * field - to be concatenated to rc to compare with fieldToCompare
171 * fieldToCompare - The value that we're comparing against
172 * compare_cb - Callback to invoke to determine if comparison should continue.
173 * Callback must be defined with DPQ_DECL_COMPARECB.
174 * rc - Variable to put the return code. Same type as (head).lpQHFirst
176 #define DPQ_REMOVE_ENTRY_CB( head, elm, field, compare_cb, fieldToCompare, rc )\
178 DPQ_FIND_ENTRY_CB( head, elm, field, compare_cb, fieldToCompare, rc );\
180 /* Was the element found? */ \
183 DPQ_REMOVE( head, rc, elm ); \
188 /* Delete the entire queue
189 * head - pointer to the head of the queue
190 * field - field to access the next elements of the queue
191 * type - type of the pointer to the element element
192 * df - a delete function to be called. Declared with DPQ_DECL_DELETECB.
194 #define DPQ_DELETEQ( head, field, type, df ) \
197 while( !DPQ_IS_EMPTY(head) ) \
199 type holder = DPQ_FIRST(head); \
200 DPQ_REMOVE( head, holder, field ); \
205 /* How to define the method to be passed to DPQ_DELETEQ */
206 #define DPQ_DECL_DELETECB( name, type ) void name( type elem )
208 /* Prototype of a method which just performs a HeapFree on the elem */
209 DPQ_DECL_DELETECB( cbDeleteElemFromHeap
, LPVOID
) DECLSPEC_HIDDEN
;
211 #endif /* __WINE_DPLAYX_QUEUE_H */