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>
15 #include <afs/bubasics.h>
17 #define DLQ_ASSERT_HEAD(headptr) \
18 if ( (headptr)->dlq_type != DLQ_HEAD ) \
20 printf("file %s line %d, invalid queue head\n", \
21 __FILE__, __LINE__); \
35 DLQ_ASSERT_HEAD(headptr);
36 if ( headptr->dlq_next == headptr )
44 headptr->dlq_next = headptr;
45 headptr->dlq_prev = headptr;
46 headptr->dlq_type = DLQ_HEAD;
47 headptr->dlq_structPtr = (char *)0;
52 * link item to front of chain
54 dlqLinkf(headptr, entryptr)
58 DLQ_ASSERT_HEAD(headptr);
59 /* link in as first item in chain */
60 entryptr->dlq_next = headptr->dlq_next;
61 headptr->dlq_next->dlq_prev = entryptr;
62 entryptr->dlq_prev = headptr;
63 headptr->dlq_next = entryptr;
68 * link item to end of chain
71 dlqLinkb(headptr, entryptr)
75 DLQ_ASSERT_HEAD(headptr);
76 entryptr->dlq_next = headptr;
77 entryptr->dlq_prev = headptr->dlq_prev;
79 headptr->dlq_prev = entryptr;
80 entryptr->dlq_prev->dlq_next = entryptr;
85 * move all the items on the fromptr and append to the toptr's list
88 dlqMoveb(fromptr, toptr)
94 DLQ_ASSERT_HEAD(fromptr);
95 DLQ_ASSERT_HEAD(toptr);
97 if ( dlqEmpty(fromptr) )
100 tailptr = toptr->dlq_prev;
102 tailptr->dlq_next = fromptr->dlq_next;
103 tailptr->dlq_next->dlq_prev = tailptr;
105 /* now fix up the last item in the new chain */
106 tailptr = fromptr->dlq_prev;
108 tailptr->dlq_next = toptr;
109 toptr->dlq_prev = tailptr;
111 fromptr->dlq_next = fromptr;
112 fromptr->dlq_prev = fromptr;
116 * unlink the last item on the queue
124 DLQ_ASSERT_HEAD(headptr);
126 if ( dlqEmpty(headptr) )
129 ptr = headptr->dlq_prev;
130 ptr->dlq_prev->dlq_next = headptr;
131 headptr->dlq_prev = ptr->dlq_prev;
139 * unlink the item on the front of the queue
147 DLQ_ASSERT_HEAD(headptr);
149 if ( dlqEmpty(headptr) )
152 ptr = headptr->dlq_next;
154 headptr->dlq_next = ptr->dlq_next;
155 ptr->dlq_next->dlq_prev = headptr;
163 * unlink the specified item from the queue.
169 /* must not be the queue head */
170 if ( ptr->dlq_type == DLQ_HEAD )
172 printf("dlqUnlink: invalid unlink\n");
176 ptr->dlq_prev->dlq_next = ptr->dlq_next;
177 ptr->dlq_next->dlq_prev = ptr->dlq_prev;
184 * return point to item at front of queuen
191 DLQ_ASSERT_HEAD(headptr);
193 if ( dlqEmpty(headptr) )
196 return(headptr->dlq_next);
206 DLQ_ASSERT_HEAD(headptr);
208 ptr = headptr->dlq_next;
209 while ( ptr != headptr )
217 dlqTraverseQueue(headptr, fn1, fn2)
222 dlqlinkP ptr, oldPtr;
224 DLQ_ASSERT_HEAD(headptr);
226 ptr = headptr->dlq_next;
227 while ( ptr != headptr )
229 if (fn2 && ptr->dlq_structPtr)
230 (*fn2)(ptr->dlq_structPtr);
233 if (fn1) (*fn1)(oldPtr);