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 * 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
34 #define DPQ_INSERT(a,b,c) DPQ_INSERT_IN_TAIL(a,b,c)
37 * Tail queue definitions.
39 #define DPQ_HEAD(type) \
41 struct type *lpQHFirst; /* first element */ \
42 struct type **lpQHLast; /* addr of last next element */ \
45 #define DPQ_ENTRY(type) \
47 struct type *lpQNext; /* next element */ \
48 struct type **lpQPrev; /* address of previous next element */ \
52 * Tail queue functions.
54 #define DPQ_INIT(head) \
56 (head).lpQHFirst = NULL; \
57 (head).lpQHLast = &(head).lpQHFirst; \
60 /* Front of the queue */
61 #define DPQ_FIRST( head ) ( (head).lpQHFirst )
63 /* Check if the queue has any elements */
64 #define DPQ_IS_EMPTY( head ) ( DPQ_FIRST(head) == NULL )
66 /* Next entry -- FIXME: Convert everything over to this macro ... */
67 #define DPQ_NEXT( elem ) (elem).lpQNext
69 #define DPQ_IS_ENDOFLIST( elem ) \
70 ( DPQ_NEXT(elem) == NULL )
72 /* Insert element at end of queue */
73 #define DPQ_INSERT_IN_TAIL(head, elm, field) \
75 (elm)->field.lpQNext = NULL; \
76 (elm)->field.lpQPrev = (head).lpQHLast; \
77 *(head).lpQHLast = (elm); \
78 (head).lpQHLast = &(elm)->field.lpQNext; \
81 /* Remove element from the queue */
82 #define DPQ_REMOVE(head, elm, field) \
84 if (((elm)->field.lpQNext) != NULL) \
85 (elm)->field.lpQNext->field.lpQPrev = \
86 (elm)->field.lpQPrev; \
88 (head).lpQHLast = (elm)->field.lpQPrev; \
89 *(elm)->field.lpQPrev = (elm)->field.lpQNext; \
92 /* head - pointer to DPQ_HEAD struct
93 * elm - how to find the next element
94 * field - to be concatenated to rc to compare with fieldToCompare
95 * fieldToCompare - The value that we're comparing against
96 * fieldCompareOperator - The logical operator to compare field and
98 * rc - Variable to put the return code. Same type as (head).lpQHFirst
100 #define DPQ_FIND_ENTRY( head, elm, field, fieldCompareOperator, fieldToCompare, rc )\
102 (rc) = DPQ_FIRST(head); /* NULL head? */ \
106 /* What we're searching for? */ \
107 if( (rc)->field fieldCompareOperator (fieldToCompare) ) \
109 break; /* rc == correct element */ \
112 /* End of list check */ \
113 if( ( (rc) = (rc)->elm.lpQNext ) == (head).lpQHFirst ) \
121 /* head - pointer to DPQ_HEAD struct
122 * elm - how to find the next element
123 * field - to be concatenated to rc to compare with fieldToCompare
124 * fieldToCompare - The value that we're comparing against
125 * compare_cb - Callback to invoke to determine if comparision should continue.
126 * Callback must be defined with DPQ_DECL_COMPARECB.
127 * rc - Variable to put the return code. Same type as (head).lpQHFirst
129 #define DPQ_FIND_ENTRY_CB( head, elm, field, compare_cb, fieldToCompare, rc )\
131 (rc) = DPQ_FIRST(head); /* NULL head? */ \
135 /* What we're searching for? */ \
136 if( compare_cb( &((rc)->field), &(fieldToCompare) ) ) \
138 break; /* no more */ \
141 /* End of list check */ \
142 if( ( (rc) = (rc)->elm.lpQNext ) == (head).lpQHFirst ) \
150 /* How to define the method to be passed to DPQ_DELETEQ */
151 #define DPQ_DECL_COMPARECB( name, type ) BOOL name( const type* elem1, const type* elem2 )
154 /* head - pointer to DPQ_HEAD struct
155 * elm - how to find the next element
156 * field - to be concatenated to rc to compare with fieldToEqual
157 * fieldToCompare - The value that we're comparing against
158 * fieldCompareOperator - The logical operator to compare field and
160 * rc - Variable to put the return code. Same type as (head).lpQHFirst
162 #define DPQ_REMOVE_ENTRY( head, elm, field, fieldCompareOperator, fieldToCompare, rc )\
164 DPQ_FIND_ENTRY( head, elm, field, fieldCompareOperator, fieldToCompare, rc );\
166 /* Was the element found? */ \
169 DPQ_REMOVE( head, rc, elm ); \
173 /* head - pointer to DPQ_HEAD struct
174 * elm - how to find the next element
175 * field - to be concatenated to rc to compare with fieldToCompare
176 * fieldToCompare - The value that we're comparing against
177 * compare_cb - Callback to invoke to determine if comparision should continue.
178 * Callback must be defined with DPQ_DECL_COMPARECB.
179 * rc - Variable to put the return code. Same type as (head).lpQHFirst
181 #define DPQ_REMOVE_ENTRY_CB( head, elm, field, compare_cb, fieldToCompare, rc )\
183 DPQ_FIND_ENTRY_CB( head, elm, field, compare_cb, fieldToCompare, rc );\
185 /* Was the element found? */ \
188 DPQ_REMOVE( head, rc, elm ); \
193 /* Delete the entire queue
194 * head - pointer to the head of the queue
195 * field - field to access the next elements of the queue
196 * type - type of the pointer to the element element
197 * df - a delete function to be called. Declared with DPQ_DECL_DELETECB.
199 #define DPQ_DELETEQ( head, field, type, df ) \
202 while( !DPQ_IS_EMPTY(head) ) \
204 type holder = DPQ_FIRST(head); \
205 DPQ_REMOVE( head, holder, field ); \
210 /* How to define the method to be passed to DPQ_DELETEQ */
211 #define DPQ_DECL_DELETECB( name, type ) void name( type elem )
213 /* Prototype of a method which just performs a HeapFree on the elem */
214 DPQ_DECL_DELETECB( cbDeleteElemFromHeap
, LPVOID
);
216 #endif /* __WINE_DPLAYX_QUEUE_H */