source: trunk/src/DPlayX/dplayx_queue.h@ 4314

Last change on this file since 4314 was 4314, checked in by hugh, 25 years ago

Updated to latest wine version

File size: 5.8 KB
Line 
1/* A queue definition based on sys/queue.h TAILQ definitions
2 *
3 * Blame any implementation mistakes on Peter Hunnisett
4 * <hunnise@nortelnetworks.com>
5 */
6
7#ifndef __WINE_DPLAYX_QUEUE_H
8#define __WINE_DPLAYX_QUEUE_H
9
10#include "winbase.h"
11
12#define DPQ_INSERT(a,b,c) DPQ_INSERT_IN_TAIL(a,b,c)
13
14/*
15 * Tail queue definitions.
16 */
17#define DPQ_HEAD(type) \
18struct { \
19 struct type *lpQHFirst; /* first element */ \
20 struct type **lpQHLast; /* addr of last next element */ \
21}
22
23#define DPQ_ENTRY(type) \
24struct { \
25 struct type *lpQNext; /* next element */ \
26 struct type **lpQPrev; /* address of previous next element */ \
27}
28
29/*
30 * Tail queue functions.
31 */
32#define DPQ_INIT(head) \
33do{ \
34 (head).lpQHFirst = NULL; \
35 (head).lpQHLast = &(head).lpQHFirst; \
36} while(0)
37
38/* Front of the queue */
39#define DPQ_FIRST( head ) ( (head).lpQHFirst )
40
41/* Check if the queue has any elements */
42#define DPQ_IS_EMPTY( head ) ( DPQ_FIRST(head) == NULL )
43
44/* Next entry -- FIXME: Convert everything over to this macro ... */
45#define DPQ_NEXT( elem ) (elem).lpQNext
46
47#define DPQ_IS_ENDOFLIST( elem ) \
48 ( DPQ_NEXT(elem) == NULL )
49
50/* Insert element at end of queue */
51#define DPQ_INSERT_IN_TAIL(head, elm, field) \
52do { \
53 (elm)->field.lpQNext = NULL; \
54 (elm)->field.lpQPrev = (head).lpQHLast; \
55 *(head).lpQHLast = (elm); \
56 (head).lpQHLast = &(elm)->field.lpQNext; \
57} while(0)
58
59/* Remove element from the queue */
60#define DPQ_REMOVE(head, elm, field) \
61do { \
62 if (((elm)->field.lpQNext) != NULL) \
63 (elm)->field.lpQNext->field.lpQPrev = \
64 (elm)->field.lpQPrev; \
65 else \
66 (head).lpQHLast = (elm)->field.lpQPrev; \
67 *(elm)->field.lpQPrev = (elm)->field.lpQNext; \
68} while(0)
69
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
75 * fieldToCompare.
76 * rc - Variable to put the return code. Same type as (head).lpQHFirst
77 */
78#define DPQ_FIND_ENTRY( head, elm, field, fieldCompareOperator, fieldToCompare, rc )\
79do { \
80 (rc) = (head).lpQHFirst; /* NULL head? */ \
81 \
82 while( rc ) \
83 { \
84 /* What we're searching for? */ \
85 if( (rc)->field fieldCompareOperator (fieldToCompare) ) \
86 { \
87 break; /* rc == correct element */ \
88 } \
89 \
90 /* End of list check */ \
91 if( ( (rc) = (rc)->elm.lpQNext ) == (head).lpQHFirst ) \
92 { \
93 rc = NULL; \
94 break; \
95 } \
96 } \
97} while(0)
98
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 fieldToEqual
102 * fieldToCompare - The value that we're comparing against
103 * fieldCompareOperator - The logical operator to compare field and
104 * fieldToCompare.
105 * rc - Variable to put the return code. Same type as (head).lpQHFirst
106 */
107#define DPQ_REMOVE_ENTRY( head, elm, field, fieldCompareOperator, fieldToCompare, rc )\
108do { \
109 DPQ_FIND_ENTRY( head, elm, field, fieldCompareOperator, fieldToCompare, rc );\
110 \
111 /* Was the element found? */ \
112 if( rc ) \
113 { \
114 DPQ_REMOVE( head, rc, elm ); \
115 } \
116} while(0)
117
118/* Delete the entire queue
119 * head - pointer to the head of the queue
120 * field - field to access the next elements of the queue
121 * type - type of the pointer to the element element
122 * df - a delete function to be called. Declared with DPQ_DECL_DELETECB.
123 */
124#define DPQ_DELETEQ( head, field, type, df ) \
125while( !DPQ_IS_EMPTY(head) ) \
126{ \
127 type holder = (head).lpQHFirst; \
128 DPQ_REMOVE( head, holder, field ); \
129 df( holder ); \
130}
131
132/* How to define the method to be passed to DPQ_DELETEQ */
133#define DPQ_DECL_DELETECB( name, type ) void name( type elem )
134
135/* Prototype of a method which just performs a HeapFree on the elem */
136DPQ_DECL_DELETECB( cbDeleteElemFromHeap, LPVOID );
137
138#endif /* __WINE_DPLAYX_QUEUE_H */
Note: See TracBrowser for help on using the repository browser.