2 * Copyright 2000, International Business Machines Corporation and others.
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
10 /* Copyright (C) 1994 Cazamar Systems, Inc. */
12 #ifndef _OSI_QUEUE_H_ENV_
13 #define _OSI_QUEUE_H_ENV_ 1
15 /* this package implements a doubly linked queue of elements.
16 * Each element starts with an osi_queue_t element.
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
26 * Some of these things are macros for performance reasons.
29 typedef struct osi_queue {
30 struct osi_queue *nextp;
31 struct osi_queue *prevp;
34 typedef struct osi_queueData {
39 /* # of elements to allocate at once */
40 #define OSI_NQDALLOC 64
42 /* add an element to the head of a queue, first parm is
43 * address of head pointer, and second parm is addr of
46 extern void osi_QAdd(osi_queue_t **headpp, osi_queue_t *eltp);
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.
52 extern void osi_QAddT(osi_queue_t **headpp, osi_queue_t **tailpp, osi_queue_t *eltp);
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);
57 /* remove an element from a queue; takes address of head list, and
58 * element to remove as parameters.
60 extern void osi_QRemove(osi_queue_t **headpp, osi_queue_t *eltp);
62 /* initialize the queue package */
63 extern void osi_InitQueue(void);
65 /* allocate a queue element with one data ptr */
66 extern osi_queueData_t *osi_QDAlloc(void);
68 /* free a single element queue pointer */
69 extern void osi_QDFree(osi_queueData_t *);
71 /* retrieve the queue data from a one-element block */
72 #define osi_GetQData(x) ((x)->datap)
74 /* set the queue data in a one-element block */
75 #define osi_SetQData(x,y) ((x)->datap = (y))
77 /* get the next ptr from a queue element */
78 #define osi_QNext(x) ((x)->nextp)
80 /* get the prev ptr from a queue element */
81 #define osi_QPrev(x) ((x)->prevp)
83 /* find out if a queue is empty */
84 #define osi_QIsEmpty(x) ((*x) == ((osi_queue_t *) 0))
86 #endif /* _OSI_QUEUE_H_ENV_ */