4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Copyright (c) 1991, 1993
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * The Regents of the University of California. All rights reserved.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow *
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Redistribution and use in source and binary forms, with or without
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * modification, are permitted provided that the following conditions
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * are met:
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * 1. Redistributions of source code must retain the above copyright
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * notice, this list of conditions and the following disclaimer.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * 2. Redistributions in binary form must reproduce the above copyright
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * notice, this list of conditions and the following disclaimer in the
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * documentation and/or other materials provided with the distribution.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * 3. All advertising materials mentioning features or use of this software
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * must display the following acknowledgement:
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * This product includes software developed by the University of
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * California, Berkeley and its contributors.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * 4. Neither the name of the University nor the names of its contributors
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * may be used to endorse or promote products derived from this software
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * without specific prior written permission.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow *
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * SUCH DAMAGE.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow *
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * @(#)queue.h 8.5 (Berkeley) 8/20/94
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#pragma ident "%Z%%M% %I% %E% SMI"
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * This file [used to define] five types of data structures:
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * singly-linked lists, ...
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * [ all other types of lists removed ]
4bff34e37def8a90f9194d81bc345c52ba20086athurlow *
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Using excerpts of FreeBSD 4.5 sys/queue.h here,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * but only temporarily, until rcfile.c is replaced
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * by SMF integration code.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow *
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Yes we also have queue.h in uts/common/fs/smbclnt
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * but don't want to make that part of the exported
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * interface to the user-level code.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Singly-linked List declarations.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define SLIST_HEAD(name, type) \
4bff34e37def8a90f9194d81bc345c52ba20086athurlowstruct name { \
4bff34e37def8a90f9194d81bc345c52ba20086athurlow struct type *slh_first; /* first element */ \
4bff34e37def8a90f9194d81bc345c52ba20086athurlow}
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define SLIST_ENTRY(type) \
4bff34e37def8a90f9194d81bc345c52ba20086athurlowstruct { \
4bff34e37def8a90f9194d81bc345c52ba20086athurlow struct type *sle_next; /* next element */ \
4bff34e37def8a90f9194d81bc345c52ba20086athurlow}
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Singly-linked List functions.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define SLIST_EMPTY(head) ((head)->slh_first == NULL)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define SLIST_FIRST(head) ((head)->slh_first)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define SLIST_FOREACH(var, head, field) \
4bff34e37def8a90f9194d81bc345c52ba20086athurlow for ((var) = SLIST_FIRST((head)); \
4bff34e37def8a90f9194d81bc345c52ba20086athurlow (var); \
4bff34e37def8a90f9194d81bc345c52ba20086athurlow (var) = SLIST_NEXT((var), field))
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define SLIST_INIT(head) do { \
4bff34e37def8a90f9194d81bc345c52ba20086athurlow SLIST_FIRST((head)) = NULL; \
4bff34e37def8a90f9194d81bc345c52ba20086athurlow} while (0)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define SLIST_INSERT_AFTER(slistelm, elm, field) do { \
4bff34e37def8a90f9194d81bc345c52ba20086athurlow SLIST_NEXT((elm), field) = SLIST_NEXT((slistelm), field); \
4bff34e37def8a90f9194d81bc345c52ba20086athurlow SLIST_NEXT((slistelm), field) = (elm); \
4bff34e37def8a90f9194d81bc345c52ba20086athurlow} while (0)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define SLIST_INSERT_HEAD(head, elm, field) do { \
4bff34e37def8a90f9194d81bc345c52ba20086athurlow SLIST_NEXT((elm), field) = SLIST_FIRST((head)); \
4bff34e37def8a90f9194d81bc345c52ba20086athurlow SLIST_FIRST((head)) = (elm); \
4bff34e37def8a90f9194d81bc345c52ba20086athurlow} while (0)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define SLIST_NEXT(elm, field) ((elm)->field.sle_next)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define SLIST_REMOVE(head, elm, type, field) do { \
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (SLIST_FIRST((head)) == (elm)) { \
4bff34e37def8a90f9194d81bc345c52ba20086athurlow SLIST_REMOVE_HEAD((head), field); \
4bff34e37def8a90f9194d81bc345c52ba20086athurlow } \
4bff34e37def8a90f9194d81bc345c52ba20086athurlow else { \
4bff34e37def8a90f9194d81bc345c52ba20086athurlow struct type *curelm = SLIST_FIRST((head)); \
4bff34e37def8a90f9194d81bc345c52ba20086athurlow while (SLIST_NEXT(curelm, field) != (elm)) \
4bff34e37def8a90f9194d81bc345c52ba20086athurlow curelm = SLIST_NEXT(curelm, field); \
4bff34e37def8a90f9194d81bc345c52ba20086athurlow SLIST_NEXT(curelm, field) = \
4bff34e37def8a90f9194d81bc345c52ba20086athurlow SLIST_NEXT(SLIST_NEXT(curelm, field), field); \
4bff34e37def8a90f9194d81bc345c52ba20086athurlow } \
4bff34e37def8a90f9194d81bc345c52ba20086athurlow} while (0)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define SLIST_REMOVE_HEAD(head, field) do { \
4bff34e37def8a90f9194d81bc345c52ba20086athurlow SLIST_FIRST((head)) = SLIST_NEXT(SLIST_FIRST((head)), field); \
4bff34e37def8a90f9194d81bc345c52ba20086athurlow} while (0)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow