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 #include <afs/param.h>
19 /* critical section protecting allocation of osi_queueData_t elements */
22 /* free list of queue elements */
23 osi_queueData_t *osi_QDFreeListp = NULL;
25 void osi_QAdd(osi_queue_t **headpp, osi_queue_t *eltp)
29 /* and both paths do the following; do this early to keep
30 * machine busy while processing delay on conditional check
35 /* there is one element here */
44 /* and both paths do the following */
48 void osi_QAddH(osi_queue_t **headpp, osi_queue_t **tailpp, osi_queue_t *eltp)
52 /* and both paths do the following; do this early to keep
53 * machine busy while processing delay on conditional check
58 /* there is one element here */
68 /* and both paths do the following */
72 void osi_QAddT(osi_queue_t **headpp, osi_queue_t **tailpp, osi_queue_t *eltp)
79 /* there's at least one element in the list; append ourselves */
85 /* we're the only element in the list */
92 void osi_QRemove(osi_queue_t **headpp, osi_queue_t *eltp)
94 osi_queue_t *np = eltp->nextp; /* next dude */
95 osi_queue_t *pp = eltp->prevp; /* prev dude */
97 if (eltp == *headpp) {
98 /* we're the first element in the list */
112 void osi_QRemoveHT(osi_queue_t **headpp, osi_queue_t **tailpp, osi_queue_t *eltp)
114 osi_queue_t *np = eltp->nextp; /* next dude */
115 osi_queue_t *pp = eltp->prevp; /* prev dude */
117 if (eltp == *headpp && eltp == *tailpp)
119 *headpp = *tailpp = NULL;
121 else if (eltp == *headpp) {
122 /* we're the first element in the list */
127 else if (eltp == *tailpp) {
128 /* we're the last element in the list */
143 void osi_InitQueue(void)
145 static int initd = 0;
150 thrd_InitCrit(&osi_qdcrit);
153 osi_queueData_t *osi_QDAlloc(void)
158 thrd_EnterCrit(&osi_qdcrit);
159 if (tp = osi_QDFreeListp) {
160 osi_QDFreeListp = (osi_queueData_t *) tp->q.nextp;
163 /* need to allocate a block more */
164 tp = (osi_queueData_t *) malloc(OSI_NQDALLOC * sizeof(osi_queueData_t));
166 /* leave last guy off of the free list; this is the one we'll
169 for(i=0; i<OSI_NQDALLOC-1; i++, tp++) {
170 tp->q.nextp = (osi_queue_t *) osi_QDFreeListp;
172 osi_QDFreeListp = tp;
175 /* when we get here, tp is pointing to the last dude allocated.
176 * This guy wasn't put on the free list, so we can return him now.
180 thrd_LeaveCrit(&osi_qdcrit);
182 osi_assertx(tp->datap == NULL, "queue freelist screwup");
187 void osi_QDFree(osi_queueData_t *qp)
189 thrd_EnterCrit(&osi_qdcrit);
190 qp->q.nextp = (osi_queue_t *) osi_QDFreeListp;
192 osi_QDFreeListp = qp;
193 thrd_LeaveCrit(&osi_qdcrit);