2 * Copyright (C) 1998, 1989 Transarc Corporation - All rights reserved
4 * (C) COPYRIGHT IBM CORPORATION 1987, 1988
5 * LICENSED MATERIALS - PROPERTY OF IBM
9 /* Copyright (C) 1994 Cazamar Systems, Inc. */
11 #include <afs/param.h>
20 /* critical section protecting allocation of osi_queueData_t elements */
23 /* free list of queue elements */
24 osi_queueData_t *osi_QDFreeListp = NULL;
26 void osi_QAdd(osi_queue_t **headpp, osi_queue_t *eltp)
30 /* and both paths do the following; do this early to keep
31 * machine busy while processing delay on conditional check
36 /* there is one element here */
45 /* and both paths do the following */
49 void osi_QAddH(osi_queue_t **headpp, osi_queue_t **tailpp, osi_queue_t *eltp)
53 /* and both paths do the following; do this early to keep
54 * machine busy while processing delay on conditional check
59 /* there is one element here */
69 /* and both paths do the following */
73 void osi_QAddT(osi_queue_t **headpp, osi_queue_t **tailpp, osi_queue_t *eltp)
80 /* there's at least one element in the list; append ourselves */
86 /* we're the only element in the list */
93 void osi_QRemove(osi_queue_t **headpp, osi_queue_t *eltp)
95 osi_queue_t *np; /* next dude */
97 np = eltp->nextp; /* useful for both paths */
99 if (eltp == *headpp) {
100 /* we're the first element in the list */
102 if (np) np->prevp = NULL;
105 eltp->prevp->nextp = np;
106 if (np) np->prevp = eltp->prevp;
110 void osi_InitQueue(void)
112 static int initd = 0;
117 thrd_InitCrit(&osi_qdcrit);
120 osi_queueData_t *osi_QDAlloc(void)
125 thrd_EnterCrit(&osi_qdcrit);
126 if (tp = osi_QDFreeListp) {
127 osi_QDFreeListp = (osi_queueData_t *) tp->q.nextp;
130 /* need to allocate a block more */
131 tp = (osi_queueData_t *) malloc(OSI_NQDALLOC * sizeof(osi_queueData_t));
133 /* leave last guy off of the free list; this is the one we'll
136 for(i=0; i<OSI_NQDALLOC-1; i++, tp++) {
137 tp->q.nextp = (osi_queue_t *) osi_QDFreeListp;
139 osi_QDFreeListp = tp;
142 /* when we get here, tp is pointing to the last dude allocated.
143 * This guy wasn't put on the free list, so we can return him now.
147 thrd_LeaveCrit(&osi_qdcrit);
149 osi_assertx(tp->datap == NULL, "queue freelist screwup");
154 void osi_QDFree(osi_queueData_t *qp)
156 thrd_EnterCrit(&osi_qdcrit);
157 qp->q.nextp = (osi_queue_t *) osi_QDFreeListp;
159 osi_QDFreeListp = qp;
160 thrd_LeaveCrit(&osi_qdcrit);