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 <afs/param.h>
11 #include <afs/bubasics.h>
13 #define DLQ_ASSERT_HEAD(headptr) \
14 if ( (headptr)->dlq_type != DLQ_HEAD ) \
16 printf("file %s line %d, invalid queue head\n", \
17 __FILE__, __LINE__); \
31 DLQ_ASSERT_HEAD(headptr);
32 if ( headptr->dlq_next == headptr )
40 headptr->dlq_next = headptr;
41 headptr->dlq_prev = headptr;
42 headptr->dlq_type = DLQ_HEAD;
43 headptr->dlq_structPtr = (char *)0;
48 * link item to front of chain
50 dlqLinkf(headptr, entryptr)
54 DLQ_ASSERT_HEAD(headptr);
55 /* link in as first item in chain */
56 entryptr->dlq_next = headptr->dlq_next;
57 headptr->dlq_next->dlq_prev = entryptr;
58 entryptr->dlq_prev = headptr;
59 headptr->dlq_next = entryptr;
64 * link item to end of chain
67 dlqLinkb(headptr, entryptr)
71 DLQ_ASSERT_HEAD(headptr);
72 entryptr->dlq_next = headptr;
73 entryptr->dlq_prev = headptr->dlq_prev;
75 headptr->dlq_prev = entryptr;
76 entryptr->dlq_prev->dlq_next = entryptr;
81 * move all the items on the fromptr and append to the toptr's list
84 dlqMoveb(fromptr, toptr)
90 DLQ_ASSERT_HEAD(fromptr);
91 DLQ_ASSERT_HEAD(toptr);
93 if ( dlqEmpty(fromptr) )
96 tailptr = toptr->dlq_prev;
98 tailptr->dlq_next = fromptr->dlq_next;
99 tailptr->dlq_next->dlq_prev = tailptr;
101 /* now fix up the last item in the new chain */
102 tailptr = fromptr->dlq_prev;
104 tailptr->dlq_next = toptr;
105 toptr->dlq_prev = tailptr;
107 fromptr->dlq_next = fromptr;
108 fromptr->dlq_prev = fromptr;
112 * unlink the last item on the queue
120 DLQ_ASSERT_HEAD(headptr);
122 if ( dlqEmpty(headptr) )
125 ptr = headptr->dlq_prev;
126 ptr->dlq_prev->dlq_next = headptr;
127 headptr->dlq_prev = ptr->dlq_prev;
135 * unlink the item on the front of the queue
143 DLQ_ASSERT_HEAD(headptr);
145 if ( dlqEmpty(headptr) )
148 ptr = headptr->dlq_next;
150 headptr->dlq_next = ptr->dlq_next;
151 ptr->dlq_next->dlq_prev = headptr;
159 * unlink the specified item from the queue.
165 /* must not be the queue head */
166 if ( ptr->dlq_type == DLQ_HEAD )
168 printf("dlqUnlink: invalid unlink\n");
172 ptr->dlq_prev->dlq_next = ptr->dlq_next;
173 ptr->dlq_next->dlq_prev = ptr->dlq_prev;
180 * return point to item at front of queuen
187 DLQ_ASSERT_HEAD(headptr);
189 if ( dlqEmpty(headptr) )
192 return(headptr->dlq_next);
202 DLQ_ASSERT_HEAD(headptr);
204 ptr = headptr->dlq_next;
205 while ( ptr != headptr )
213 dlqTraverseQueue(headptr, fn1, fn2)
218 dlqlinkP ptr, oldPtr;
220 DLQ_ASSERT_HEAD(headptr);
222 ptr = headptr->dlq_next;
223 while ( ptr != headptr )
225 if (fn2 && ptr->dlq_structPtr)
226 (*fn2)(ptr->dlq_structPtr);
229 if (fn1) (*fn1)(oldPtr);