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
93 dlqMoveb(fromptr, toptr)
99 DLQ_ASSERT_HEAD(fromptr);
100 DLQ_ASSERT_HEAD(toptr);
102 if (dlqEmpty(fromptr))
105 tailptr = toptr->dlq_prev;
107 tailptr->dlq_next = fromptr->dlq_next;
108 tailptr->dlq_next->dlq_prev = tailptr;
110 /* now fix up the last item in the new chain */
111 tailptr = fromptr->dlq_prev;
113 tailptr->dlq_next = toptr;
114 toptr->dlq_prev = tailptr;
116 fromptr->dlq_next = fromptr;
117 fromptr->dlq_prev = fromptr;
122 * unlink the last item on the queue
130 DLQ_ASSERT_HEAD(headptr);
132 if (dlqEmpty(headptr))
135 ptr = headptr->dlq_prev;
136 ptr->dlq_prev->dlq_next = headptr;
137 headptr->dlq_prev = ptr->dlq_prev;
145 * unlink the item on the front of the queue
153 DLQ_ASSERT_HEAD(headptr);
155 if (dlqEmpty(headptr))
158 ptr = headptr->dlq_next;
160 headptr->dlq_next = ptr->dlq_next;
161 ptr->dlq_next->dlq_prev = headptr;
169 * unlink the specified item from the queue.
175 /* must not be the queue head */
176 if (ptr->dlq_type == DLQ_HEAD) {
177 printf("dlqUnlink: invalid unlink\n");
181 ptr->dlq_prev->dlq_next = ptr->dlq_next;
182 ptr->dlq_next->dlq_prev = ptr->dlq_prev;
189 * return point to item at front of queuen
196 DLQ_ASSERT_HEAD(headptr);
198 if (dlqEmpty(headptr))
201 return (headptr->dlq_next);
211 DLQ_ASSERT_HEAD(headptr);
213 ptr = headptr->dlq_next;
214 while (ptr != headptr) {
221 dlqTraverseQueue(headptr, fn1, fn2)
226 dlqlinkP ptr, oldPtr;
228 DLQ_ASSERT_HEAD(headptr);
230 ptr = headptr->dlq_next;
231 while (ptr != headptr) {
232 if (fn2 && ptr->dlq_structPtr)
233 (*fn2) (ptr->dlq_structPtr);