2000-07-10 15:19:28 +02:00
|
|
|
/* A queue definition based on sys/queue.h TAILQ definitions
|
2002-06-01 01:06:46 +02:00
|
|
|
*
|
2002-03-10 00:29:33 +01:00
|
|
|
* Copyright 2000 Peter Hunnisett
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2000-05-30 22:08:32 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __WINE_DPLAYX_QUEUE_H
|
|
|
|
#define __WINE_DPLAYX_QUEUE_H
|
|
|
|
|
2000-08-25 23:58:05 +02:00
|
|
|
#include "winbase.h"
|
|
|
|
|
2000-07-10 15:19:28 +02:00
|
|
|
#define DPQ_INSERT(a,b,c) DPQ_INSERT_IN_TAIL(a,b,c)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Tail queue definitions.
|
|
|
|
*/
|
|
|
|
#define DPQ_HEAD(type) \
|
|
|
|
struct { \
|
|
|
|
struct type *lpQHFirst; /* first element */ \
|
|
|
|
struct type **lpQHLast; /* addr of last next element */ \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define DPQ_ENTRY(type) \
|
|
|
|
struct { \
|
|
|
|
struct type *lpQNext; /* next element */ \
|
|
|
|
struct type **lpQPrev; /* address of previous next element */ \
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Tail queue functions.
|
|
|
|
*/
|
|
|
|
#define DPQ_INIT(head) \
|
|
|
|
do{ \
|
|
|
|
(head).lpQHFirst = NULL; \
|
|
|
|
(head).lpQHLast = &(head).lpQHFirst; \
|
|
|
|
} while(0)
|
|
|
|
|
2000-08-25 23:58:05 +02:00
|
|
|
/* Front of the queue */
|
|
|
|
#define DPQ_FIRST( head ) ( (head).lpQHFirst )
|
|
|
|
|
|
|
|
/* Check if the queue has any elements */
|
2002-06-01 01:06:46 +02:00
|
|
|
#define DPQ_IS_EMPTY( head ) ( DPQ_FIRST(head) == NULL )
|
2000-08-25 23:58:05 +02:00
|
|
|
|
|
|
|
/* Next entry -- FIXME: Convert everything over to this macro ... */
|
|
|
|
#define DPQ_NEXT( elem ) (elem).lpQNext
|
|
|
|
|
|
|
|
#define DPQ_IS_ENDOFLIST( elem ) \
|
|
|
|
( DPQ_NEXT(elem) == NULL )
|
|
|
|
|
|
|
|
/* Insert element at end of queue */
|
2000-07-10 15:19:28 +02:00
|
|
|
#define DPQ_INSERT_IN_TAIL(head, elm, field) \
|
|
|
|
do { \
|
|
|
|
(elm)->field.lpQNext = NULL; \
|
|
|
|
(elm)->field.lpQPrev = (head).lpQHLast; \
|
|
|
|
*(head).lpQHLast = (elm); \
|
|
|
|
(head).lpQHLast = &(elm)->field.lpQNext; \
|
|
|
|
} while(0)
|
|
|
|
|
2000-08-25 23:58:05 +02:00
|
|
|
/* Remove element from the queue */
|
2000-07-10 15:19:28 +02:00
|
|
|
#define DPQ_REMOVE(head, elm, field) \
|
|
|
|
do { \
|
|
|
|
if (((elm)->field.lpQNext) != NULL) \
|
|
|
|
(elm)->field.lpQNext->field.lpQPrev = \
|
|
|
|
(elm)->field.lpQPrev; \
|
|
|
|
else \
|
|
|
|
(head).lpQHLast = (elm)->field.lpQPrev; \
|
|
|
|
*(elm)->field.lpQPrev = (elm)->field.lpQNext; \
|
|
|
|
} while(0)
|
2000-05-30 22:08:32 +02:00
|
|
|
|
2000-07-10 15:19:28 +02:00
|
|
|
/* head - pointer to DPQ_HEAD struct
|
2000-05-30 22:08:32 +02:00
|
|
|
* elm - how to find the next element
|
2000-08-25 23:58:05 +02:00
|
|
|
* field - to be concatenated to rc to compare with fieldToCompare
|
|
|
|
* fieldToCompare - The value that we're comparing against
|
|
|
|
* fieldCompareOperator - The logical operator to compare field and
|
2002-06-01 01:06:46 +02:00
|
|
|
* fieldToCompare.
|
2000-07-10 15:19:28 +02:00
|
|
|
* rc - Variable to put the return code. Same type as (head).lpQHFirst
|
2000-05-30 22:08:32 +02:00
|
|
|
*/
|
2000-08-25 23:58:05 +02:00
|
|
|
#define DPQ_FIND_ENTRY( head, elm, field, fieldCompareOperator, fieldToCompare, rc )\
|
2000-07-10 15:19:28 +02:00
|
|
|
do { \
|
2000-09-27 01:11:48 +02:00
|
|
|
(rc) = DPQ_FIRST(head); /* NULL head? */ \
|
2000-07-10 15:19:28 +02:00
|
|
|
\
|
|
|
|
while( rc ) \
|
|
|
|
{ \
|
|
|
|
/* What we're searching for? */ \
|
2000-08-25 23:58:05 +02:00
|
|
|
if( (rc)->field fieldCompareOperator (fieldToCompare) ) \
|
2000-07-10 15:19:28 +02:00
|
|
|
{ \
|
|
|
|
break; /* rc == correct element */ \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
/* End of list check */ \
|
|
|
|
if( ( (rc) = (rc)->elm.lpQNext ) == (head).lpQHFirst ) \
|
|
|
|
{ \
|
|
|
|
rc = NULL; \
|
|
|
|
break; \
|
|
|
|
} \
|
|
|
|
} \
|
2000-06-07 05:44:36 +02:00
|
|
|
} while(0)
|
|
|
|
|
2000-09-27 01:11:48 +02:00
|
|
|
/* head - pointer to DPQ_HEAD struct
|
|
|
|
* elm - how to find the next element
|
|
|
|
* field - to be concatenated to rc to compare with fieldToCompare
|
|
|
|
* fieldToCompare - The value that we're comparing against
|
|
|
|
* compare_cb - Callback to invoke to determine if comparision should continue.
|
2002-06-01 01:06:46 +02:00
|
|
|
* Callback must be defined with DPQ_DECL_COMPARECB.
|
2000-09-27 01:11:48 +02:00
|
|
|
* rc - Variable to put the return code. Same type as (head).lpQHFirst
|
|
|
|
*/
|
|
|
|
#define DPQ_FIND_ENTRY_CB( head, elm, field, compare_cb, fieldToCompare, rc )\
|
|
|
|
do { \
|
|
|
|
(rc) = DPQ_FIRST(head); /* NULL head? */ \
|
|
|
|
\
|
|
|
|
while( rc ) \
|
|
|
|
{ \
|
|
|
|
/* What we're searching for? */ \
|
|
|
|
if( compare_cb( &((rc)->field), &(fieldToCompare) ) ) \
|
|
|
|
{ \
|
|
|
|
break; /* no more */ \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
/* End of list check */ \
|
|
|
|
if( ( (rc) = (rc)->elm.lpQNext ) == (head).lpQHFirst ) \
|
|
|
|
{ \
|
|
|
|
rc = NULL; \
|
|
|
|
break; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
/* How to define the method to be passed to DPQ_DELETEQ */
|
|
|
|
#define DPQ_DECL_COMPARECB( name, type ) BOOL name( const type* elem1, const type* elem2 )
|
|
|
|
|
|
|
|
|
2000-07-10 15:19:28 +02:00
|
|
|
/* head - pointer to DPQ_HEAD struct
|
2000-06-07 05:44:36 +02:00
|
|
|
* elm - how to find the next element
|
|
|
|
* field - to be concatenated to rc to compare with fieldToEqual
|
2000-08-25 23:58:05 +02:00
|
|
|
* fieldToCompare - The value that we're comparing against
|
|
|
|
* fieldCompareOperator - The logical operator to compare field and
|
|
|
|
* fieldToCompare.
|
2000-07-10 15:19:28 +02:00
|
|
|
* rc - Variable to put the return code. Same type as (head).lpQHFirst
|
2000-06-07 05:44:36 +02:00
|
|
|
*/
|
2000-08-25 23:58:05 +02:00
|
|
|
#define DPQ_REMOVE_ENTRY( head, elm, field, fieldCompareOperator, fieldToCompare, rc )\
|
2000-07-10 15:19:28 +02:00
|
|
|
do { \
|
2000-08-25 23:58:05 +02:00
|
|
|
DPQ_FIND_ENTRY( head, elm, field, fieldCompareOperator, fieldToCompare, rc );\
|
2000-07-10 15:19:28 +02:00
|
|
|
\
|
|
|
|
/* Was the element found? */ \
|
|
|
|
if( rc ) \
|
|
|
|
{ \
|
|
|
|
DPQ_REMOVE( head, rc, elm ); \
|
|
|
|
} \
|
2000-06-07 05:44:36 +02:00
|
|
|
} while(0)
|
2000-05-30 22:08:32 +02:00
|
|
|
|
2000-09-27 01:11:48 +02:00
|
|
|
/* head - pointer to DPQ_HEAD struct
|
|
|
|
* elm - how to find the next element
|
|
|
|
* field - to be concatenated to rc to compare with fieldToCompare
|
|
|
|
* fieldToCompare - The value that we're comparing against
|
|
|
|
* compare_cb - Callback to invoke to determine if comparision should continue.
|
|
|
|
* Callback must be defined with DPQ_DECL_COMPARECB.
|
|
|
|
* rc - Variable to put the return code. Same type as (head).lpQHFirst
|
|
|
|
*/
|
|
|
|
#define DPQ_REMOVE_ENTRY_CB( head, elm, field, compare_cb, fieldToCompare, rc )\
|
|
|
|
do { \
|
|
|
|
DPQ_FIND_ENTRY_CB( head, elm, field, compare_cb, fieldToCompare, rc );\
|
|
|
|
\
|
|
|
|
/* Was the element found? */ \
|
|
|
|
if( rc ) \
|
|
|
|
{ \
|
|
|
|
DPQ_REMOVE( head, rc, elm ); \
|
|
|
|
} \
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
/* Delete the entire queue
|
2000-08-25 23:58:05 +02:00
|
|
|
* head - pointer to the head of the queue
|
|
|
|
* field - field to access the next elements of the queue
|
|
|
|
* type - type of the pointer to the element element
|
|
|
|
* df - a delete function to be called. Declared with DPQ_DECL_DELETECB.
|
|
|
|
*/
|
2000-09-27 01:11:48 +02:00
|
|
|
#define DPQ_DELETEQ( head, field, type, df ) \
|
|
|
|
do \
|
|
|
|
{ \
|
|
|
|
while( !DPQ_IS_EMPTY(head) ) \
|
|
|
|
{ \
|
|
|
|
type holder = DPQ_FIRST(head); \
|
|
|
|
DPQ_REMOVE( head, holder, field ); \
|
|
|
|
df( holder ); \
|
|
|
|
} \
|
|
|
|
} while(0)
|
2000-08-25 23:58:05 +02:00
|
|
|
|
|
|
|
/* How to define the method to be passed to DPQ_DELETEQ */
|
|
|
|
#define DPQ_DECL_DELETECB( name, type ) void name( type elem )
|
|
|
|
|
|
|
|
/* Prototype of a method which just performs a HeapFree on the elem */
|
|
|
|
DPQ_DECL_DELETECB( cbDeleteElemFromHeap, LPVOID );
|
|
|
|
|
2000-05-30 22:08:32 +02:00
|
|
|
#endif /* __WINE_DPLAYX_QUEUE_H */
|