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

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

Added ID tags

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