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 #include <afsconfig.h>
11 #include <afs/param.h>
19 #include <afs/bubasics.h>
21 #define DLQ_ASSERT_HEAD(headptr) \
22 if ( (headptr)->dlq_type != DLQ_HEAD ) \
24 printf("file %s line %d, invalid queue head\n", \
25 __FILE__, __LINE__); \
39 DLQ_ASSERT_HEAD(headptr);
40 if (headptr->dlq_next == headptr)
48 headptr->dlq_next = headptr;
49 headptr->dlq_prev = headptr;
50 headptr->dlq_type = DLQ_HEAD;
51 headptr->dlq_structPtr = NULL;
56 * link item to front of chain
58 dlqLinkf(headptr, entryptr)
62 DLQ_ASSERT_HEAD(headptr);
63 /* link in as first item in chain */
64 entryptr->dlq_next = headptr->dlq_next;
65 headptr->dlq_next->dlq_prev = entryptr;
66 entryptr->dlq_prev = headptr;
67 headptr->dlq_next = entryptr;
72 * link item to end of chain
75 dlqLinkb(headptr, entryptr)
79 DLQ_ASSERT_HEAD(headptr);
80 entryptr->dlq_next = headptr;
81 entryptr->dlq_prev = headptr->dlq_prev;
83 headptr->dlq_prev = entryptr;
84 entryptr->dlq_prev->dlq_next = entryptr;
89 * move all the items on the fromptr and append to the toptr's list
92 dlqMoveb(fromptr, toptr)
98 DLQ_ASSERT_HEAD(fromptr);
99 DLQ_ASSERT_HEAD(toptr);
101 if (dlqEmpty(fromptr))
104 tailptr = toptr->dlq_prev;
106 tailptr->dlq_next = fromptr->dlq_next;
107 tailptr->dlq_next->dlq_prev = tailptr;
109 /* now fix up the last item in the new chain */
110 tailptr = fromptr->dlq_prev;
112 tailptr->dlq_next = toptr;
113 toptr->dlq_prev = tailptr;
115 fromptr->dlq_next = fromptr;
116 fromptr->dlq_prev = fromptr;
121 * unlink the last item on the queue
129 DLQ_ASSERT_HEAD(headptr);
131 if (dlqEmpty(headptr))
134 ptr = headptr->dlq_prev;
135 ptr->dlq_prev->dlq_next = headptr;
136 headptr->dlq_prev = ptr->dlq_prev;
144 * unlink the item on the front of the queue
152 DLQ_ASSERT_HEAD(headptr);
154 if (dlqEmpty(headptr))
157 ptr = headptr->dlq_next;
159 headptr->dlq_next = ptr->dlq_next;
160 ptr->dlq_next->dlq_prev = headptr;
168 * unlink the specified item from the queue.
174 /* must not be the queue head */
175 if (ptr->dlq_type == DLQ_HEAD) {
176 printf("dlqUnlink: invalid unlink\n");
180 ptr->dlq_prev->dlq_next = ptr->dlq_next;
181 ptr->dlq_next->dlq_prev = ptr->dlq_prev;
188 * return point to item at front of queuen
195 DLQ_ASSERT_HEAD(headptr);
197 if (dlqEmpty(headptr))
200 return (headptr->dlq_next);
210 DLQ_ASSERT_HEAD(headptr);
212 ptr = headptr->dlq_next;
213 while (ptr != headptr) {
220 dlqTraverseQueue(headptr, fn1, fn2)
225 dlqlinkP ptr, oldPtr;
227 DLQ_ASSERT_HEAD(headptr);
229 ptr = headptr->dlq_next;
230 while (ptr != headptr) {
231 if (fn2 && ptr->dlq_structPtr)
232 (*fn2) (ptr->dlq_structPtr);