4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
30 * Routines for manipulating a FIFO queue
38 typedef struct fifonode
{
40 struct fifonode
*fn_next
;
53 f
= xcalloc(sizeof (fifo_t
));
58 /* Add to the end of the fifo */
60 fifo_add(fifo_t
*f
, void *data
)
62 fifonode_t
*fn
= xmalloc(sizeof (fifonode_t
));
67 if (f
->f_tail
== NULL
)
68 f
->f_head
= f
->f_tail
= fn
;
70 f
->f_tail
->fn_next
= fn
;
75 /* Remove from the front of the fifo */
77 fifo_remove(fifo_t
*f
)
82 if ((fn
= f
->f_head
) == NULL
)
86 if ((f
->f_head
= fn
->fn_next
) == NULL
)
96 fifo_nullfree(void *arg
)
98 /* this function intentionally left blank */
101 /* Free an entire fifo */
103 fifo_free(fifo_t
*f
, void (*freefn
)(void *))
105 fifonode_t
*fn
= f
->f_head
;
109 freefn
= fifo_nullfree
;
112 (*freefn
)(fn
->fn_data
);
128 for (i
= 0, fn
= f
->f_head
; fn
; fn
= fn
->fn_next
, i
++);
134 fifo_empty(fifo_t
*f
)
136 return (f
->f_head
== NULL
);
140 fifo_iter(fifo_t
*f
, int (*iter
)(void *data
, void *arg
), void *arg
)
146 for (fn
= f
->f_head
; fn
; fn
= fn
->fn_next
) {
147 if ((rc
= iter(fn
->fn_data
, arg
)) < 0)