cleanup-licensing-and-transarc-references-20030309
[openafs.git] / src / WINNT / client_osi / osiqueue.h
1 /* 
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 /* Copyright (C) 1994 Cazamar Systems, Inc. */
11
12 #ifndef _OSI_QUEUE_H_ENV_
13 #define _OSI_QUEUE_H_ENV_ 1
14
15 /* this package implements a doubly linked queue of elements.
16  * Each element starts with an osi_queue_t element.
17  *
18  * Utility functions are passed a pointer to a pointer to the first
19  * element in the list; this word is NULL if the list is empty (the
20  * pointer to it, of course, is not NULL).
21  * The list is *not* circularly linked; rather prevp of the first
22  * element and nextp of the last element are both NULL; this makes
23  * checking for the end of the list easier, and still provides us a
24  * quick deletion.
25  *
26  * Some of these things are macros for performance reasons.
27  */
28
29 typedef struct osi_queue {
30         struct osi_queue *nextp;
31         struct osi_queue *prevp;
32 } osi_queue_t;
33
34 typedef struct osi_queueData {
35         osi_queue_t q;
36         void *datap;
37 } osi_queueData_t;
38
39 /* # of elements to allocate at once */
40 #define OSI_NQDALLOC            64
41
42 /* add an element to the head of a queue, first parm is
43  * address of head pointer, and second parm is addr of
44  * element to add.
45  */
46 extern void osi_QAdd(osi_queue_t **headpp, osi_queue_t *eltp);
47
48 /* add an element to the tail of a queue, first parm is
49  * address of head pointer, second is addr of ptr to tail elt,
50  * and third parm is addr of element to add.
51  */
52 extern void osi_QAddT(osi_queue_t **headpp, osi_queue_t **tailpp, osi_queue_t *eltp);
53
54 /* add to the head (like osi_QAdd) only be prepared to set tailpp if necessary */
55 extern void osi_QAddH(osi_queue_t **headpp, osi_queue_t **tailpp, osi_queue_t *eltp);
56
57 /* remove an element from a queue; takes address of head list, and
58  * element to remove as parameters.
59  */
60 extern void osi_QRemove(osi_queue_t **headpp, osi_queue_t *eltp);
61
62 /* initialize the queue package */
63 extern void osi_InitQueue(void);
64
65 /* allocate a queue element with one data ptr */
66 extern osi_queueData_t *osi_QDAlloc(void);
67
68 /* free a single element queue pointer */
69 extern void osi_QDFree(osi_queueData_t *);
70
71 /* retrieve the queue data from a one-element block */
72 #define osi_GetQData(x)         ((x)->datap)
73
74 /* set the queue data in a one-element block */
75 #define osi_SetQData(x,y)       ((x)->datap = (y))
76
77 /* get the next ptr from a queue element */
78 #define osi_QNext(x)    ((x)->nextp)
79
80 /* get the prev ptr from a queue element */
81 #define osi_QPrev(x)    ((x)->prevp)
82
83 /* find out if a queue is empty */
84 #define osi_QIsEmpty(x) ((*x) == ((osi_queue_t *) 0))
85
86 #endif /* _OSI_QUEUE_H_ENV_ */