fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER START
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The contents of this file are subject to the terms of the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Common Development and Distribution License (the "License").
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You may not use this file except in compliance with the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or http://www.opensolaris.org/os/licensing.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See the License for the specific language governing permissions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and limitations under the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * When distributing Covered Code, include this CDDL HEADER in each
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If applicable, add the following below this CDDL HEADER, with the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER END
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use is subject to license terms.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifndef _NSC_LIST_H
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define _NSC_LIST_H
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef __cplusplus
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern "C" {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Generic lists support.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Lists are circular and doubly-linked, with headers.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * When a list is empty, both pointers in the header
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * point to the header itself.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if defined(_KERNEL) || defined(_KMEMUSER)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* list element */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef struct ls_elt {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct ls_elt *ls_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct ls_elt *ls_prev;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} ls_elt_t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* _KERNEL || _KMEMUSER */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef _KERNEL
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * All take as arguments side effect-free pointers to list structures
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define LS_ISEMPTY(listp) \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (((ls_elt_t *)(listp))->ls_next == (ls_elt_t *)(listp))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define LS_INIT(listp) { \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((ls_elt_t *)(listp))->ls_next = \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((ls_elt_t *)(listp))->ls_prev = \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((ls_elt_t *)(listp)); \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define LS_REMOVE(listp) ls_remove((ls_elt_t *)(listp))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * For these five, ptrs are to list elements, but qp and stackp are
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * implicitly headers.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define LS_INS_BEFORE(oldp, newp) \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ls_ins_before((ls_elt_t *)(oldp), (ls_elt_t *)(newp))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define LS_INS_AFTER(oldp, newp) \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ls_ins_after((ls_elt_t *)(oldp), (ls_elt_t *)(newp))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define LS_INSQUE(qp, eltp) \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ls_ins_before((ls_elt_t *)(qp), (ls_elt_t *)(eltp))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* result needs cast; 0 result if empty queue */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define LS_REMQUE(qp) ls_remque((ls_elt_t *)(qp))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define LS_PUSH(stackp, newp) \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ls_ins_after((ls_elt_t *)(stackp), (ls_elt_t *)(newp))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* result needs cast; 0 result if empty stack */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define LS_POP(stackp) ls_remque((ls_elt_t *)(stackp))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* public function declarations */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid ls_ins_before(ls_elt_t *, ls_elt_t *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid ls_ins_after(ls_elt_t *, ls_elt_t *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortels_elt_t *ls_remque(ls_elt_t *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid ls_remove(ls_elt_t *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* _KERNEL */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if defined(_KERNEL) || defined(_KMEMUSER)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef struct llist {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct llist *volatile flink; /* forward link */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct llist *volatile rlink; /* reverse link */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} llist_t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* _KERNEL || _KMEMUSER */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef _KERNEL
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define INITQUE(l) ((l)->flink = (l)->rlink = (l))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define EMPTYQUE(l) ((l)->flink == (l))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* _KERNEL */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef __cplusplus
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* _NSC_LIST_H */