GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / cfe / cfe / lib / lib_queue.c
blob8830eb3933056e41311ea799be6eca534b04335b
1 /* *********************************************************************
2 * Broadcom Common Firmware Environment (CFE)
3 *
4 * Queue Management routines File: lib_queue.c
5 *
6 * Routines to manage doubly-linked queues.
7 *
8 * Author: Mitch Lichtenberg (mpl@broadcom.com)
9 *
10 *********************************************************************
12 * Copyright 2000,2001,2002,2003
13 * Broadcom Corporation. All rights reserved.
15 * This software is furnished under license and may be used and
16 * copied only in accordance with the following terms and
17 * conditions. Subject to these conditions, you may download,
18 * copy, install, use, modify and distribute modified or unmodified
19 * copies of this software in source and/or binary form. No title
20 * or ownership is transferred hereby.
22 * 1) Any source code used, modified or distributed must reproduce
23 * and retain this copyright notice and list of conditions
24 * as they appear in the source file.
26 * 2) No right is granted to use any trade name, trademark, or
27 * logo of Broadcom Corporation. The "Broadcom Corporation"
28 * name may not be used to endorse or promote products derived
29 * from this software without the prior written permission of
30 * Broadcom Corporation.
32 * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR
33 * IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED
34 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
35 * PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT
36 * SHALL BROADCOM BE LIABLE FOR ANY DAMAGES WHATSOEVER, AND IN
37 * PARTICULAR, BROADCOM SHALL NOT BE LIABLE FOR DIRECT, INDIRECT,
38 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
39 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
40 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
41 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
42 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
43 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE), EVEN IF ADVISED OF
44 * THE POSSIBILITY OF SUCH DAMAGE.
45 ********************************************************************* */
48 #include "lib_types.h"
49 #include "lib_queue.h"
52 /* *********************************************************************
53 * Q_ENQUEUE(qb,item)
55 * Add item to a queue
57 * Input Parameters:
58 * qb - queue block
59 * item - item to add
61 * Return Value:
62 * Nothing.
63 ********************************************************************* */
65 void q_enqueue(queue_t *qb,queue_t *item)
67 qb->q_prev->q_next = item;
68 item->q_next = qb;
69 item->q_prev = qb->q_prev;
70 qb->q_prev = item;
74 /* *********************************************************************
75 * Q_DEQUEUE(element)
77 * Remove an element from the queue
79 * Input Parameters:
80 * element - element to remove
82 * Return Value:
83 * Nothing.
84 ********************************************************************* */
86 void q_dequeue(queue_t *item)
88 item->q_prev->q_next = item->q_next;
89 item->q_next->q_prev = item->q_prev;
93 /* *********************************************************************
94 * Q_DEQNEXT(qb)
96 * Dequeue next element from the specified queue
98 * Input Parameters:
99 * qb - queue block
101 * Return Value:
102 * next element, or NULL
103 ********************************************************************* */
105 queue_t *q_deqnext(queue_t *qb)
107 if (qb->q_next == qb) {
108 return NULL;
111 qb = qb->q_next;
113 qb->q_prev->q_next = qb->q_next;
114 qb->q_next->q_prev = qb->q_prev;
116 return qb;
120 /* *********************************************************************
121 * Q_MAP(qb)
123 * "Map" a queue, calling the specified function for each
124 * element in the queue
126 * If the function returns nonzero, q_map will terminate.
128 * Input Parameters:
129 * qb - queue block
130 * fn - function pointer
131 * a,b - parameters for the function
133 * Return Value:
134 * return value from function, or zero if entire queue
135 * was mapped.
136 ********************************************************************* */
138 int q_map(queue_t *qb, int (*func)(queue_t *,unsigned int,unsigned int),
139 unsigned int a,unsigned int b)
141 queue_t *qe;
142 queue_t *nextq;
143 int res;
145 qe = qb;
147 qe = qb->q_next;
149 while (qe != qb) {
150 nextq = qe->q_next;
151 if ((res = (*func)(qe,a,b))) return res;
152 qe = nextq;
155 return 0;
162 /* *********************************************************************
163 * Q_COUNT(qb) *
165 * Counts the elements on a queue (not interlocked) *
167 * Input Parameters: *
168 * qb - queue block *
170 * Return Value: *
171 * number of elements *
172 ********************************************************************* */
173 int q_count(queue_t *qb)
175 queue_t *qe;
176 int res = 0;
178 qe = qb;
180 while (qe->q_next != qb) {
181 qe = qe->q_next;
182 res++;
185 return res;
191 /* *********************************************************************
192 * Q_FIND(qb,item)
194 * Determines if a particular element is on a queue.
196 * Input Parameters:
197 * qb - queue block
198 * item - queue element
200 * Return Value:
201 * 0 - not on queue
202 * >0 - position on queue
203 ********************************************************************* */
204 int q_find(queue_t *qb,queue_t *item)
206 queue_t *q;
207 int res = 1;
209 q = qb->q_next;
211 while (q != item) {
212 if (q == qb) return 0;
213 q = q->q_next;
214 res++;
217 return res;