00001 /* 00002 * Copyright (c) 1991, 1993 00003 * The Regents of the University of California. All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions 00007 * are met: 00008 * 1. Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * 2. Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * 3. All advertising materials mentioning features or use of this software 00014 * must display the following acknowledgement: 00015 * This product includes software developed by the University of 00016 * California, Berkeley and its contributors. 00017 * 4. Neither the name of the University nor the names of its contributors 00018 * may be used to endorse or promote products derived from this software 00019 * without specific prior written permission. 00020 * 00021 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 00022 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00023 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00024 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 00025 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00026 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00027 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00028 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00029 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00030 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00031 * SUCH DAMAGE. 00032 * 00033 * @(#)queue.h 8.5 (Berkeley) 8/20/94 00034 * $Id: bsd-list.h,v 1.2 2008/03/25 04:28:30 tom_henderson Exp $ 00035 */ 00036 00037 // Copied from sys/queue.h in FreeBSD 00038 // Include this only if _SYS_QUEUE_H_ has not already been defined 00039 #if !defined(_NS_BSD_LIST_H_) && !defined(_SYS_QUEUE_H_) 00040 #define _NS_BSD_LIST_H_ 00041 00042 // define _SYS_QUEUE_H_ so /usr/include/sys/queue.h does not redefine 00043 #define _SYS_QUEUE_H_ 00044 00045 /* 00046 * This file defines five types of data structures: singly-linked lists, 00047 * slingly-linked tail queues, lists, tail queues, and circular queues. 00048 * 00049 * A singly-linked list is headed by a single forward pointer. The elements 00050 * are singly linked for minimum space and pointer manipulation overhead at 00051 * the expense of O(n) removal for arbitrary elements. New elements can be 00052 * added to the list after an existing element or at the head of the list. 00053 * Elements being removed from the head of the list should use the explicit 00054 * macro for this purpose for optimum efficiency. A singly-linked list may 00055 * only be traversed in the forward direction. Singly-linked lists are ideal 00056 * for applications with large datasets and few or no removals or for 00057 * implementing a LIFO queue. 00058 * 00059 * A singly-linked tail queue is headed by a pair of pointers, one to the 00060 * head of the list and the other to the tail of the list. The elements are 00061 * singly linked for minimum space and pointer manipulation overhead at the 00062 * expense of O(n) removal for arbitrary elements. New elements can be added 00063 * to the list after an existing element, at the head of the list, or at the 00064 * end of the list. Elements being removed from the head of the tail queue 00065 * should use the explicit macro for this purpose for optimum efficiency. 00066 * A singly-linked tail queue may only be traversed in the forward direction. 00067 * Singly-linked tail queues are ideal for applications with large datasets 00068 * and few or no removals or for implementing a FIFO queue. 00069 * 00070 * A list is headed by a single forward pointer (or an array of forward 00071 * pointers for a hash table header). The elements are doubly linked 00072 * so that an arbitrary element can be removed without a need to 00073 * traverse the list. New elements can be added to the list before 00074 * or after an existing element or at the head of the list. A list 00075 * may only be traversed in the forward direction. 00076 * 00077 * A tail queue is headed by a pair of pointers, one to the head of the 00078 * list and the other to the tail of the list. The elements are doubly 00079 * linked so that an arbitrary element can be removed without a need to 00080 * traverse the list. New elements can be added to the list before or 00081 * after an existing element, at the head of the list, or at the end of 00082 * the list. A tail queue may only be traversed in the forward direction. 00083 * 00084 * A circle queue is headed by a pair of pointers, one to the head of the 00085 * list and the other to the tail of the list. The elements are doubly 00086 * linked so that an arbitrary element can be removed without a need to 00087 * traverse the list. New elements can be added to the list before or after 00088 * an existing element, at the head of the list, or at the end of the list. 00089 * A circle queue may be traversed in either direction, but has a more 00090 * complex end of list detection. 00091 * 00092 * For details on the use of these macros, see the queue(3) manual page. 00093 */ 00094 00095 /* 00096 * List definitions. 00097 */ 00098 #define LIST_HEAD(name, type) \ 00099 struct name { \ 00100 type *lh_first; /* first element */ \ 00101 } 00102 00103 #define LIST_ENTRY(type) \ 00104 struct { \ 00105 type *le_next; /* next element */ \ 00106 type **le_prev; /* address of previous next element */ \ 00107 } 00108 00109 /* 00110 * List functions. 00111 */ 00112 #define LIST_INIT(head) { \ 00113 (head)->lh_first = NULL; \ 00114 } 00115 00116 #define LIST_INSERT_AFTER(listelm, elm, field) { \ 00117 if (((elm)->field.le_next = (listelm)->field.le_next) != NULL) \ 00118 (listelm)->field.le_next->field.le_prev = \ 00119 &(elm)->field.le_next; \ 00120 (listelm)->field.le_next = (elm); \ 00121 (elm)->field.le_prev = &(listelm)->field.le_next; \ 00122 } 00123 00124 #define LIST_INSERT_BEFORE(listelm, elm, field) { \ 00125 (elm)->field.le_prev = (listelm)->field.le_prev; \ 00126 (elm)->field.le_next = (listelm); \ 00127 *(listelm)->field.le_prev = (elm); \ 00128 (listelm)->field.le_prev = &(elm)->field.le_next; \ 00129 } 00130 00131 #define LIST_INSERT_HEAD(head, elm, field) { \ 00132 if (((elm)->field.le_next = (head)->lh_first) != NULL) \ 00133 (head)->lh_first->field.le_prev = &(elm)->field.le_next;\ 00134 (head)->lh_first = (elm); \ 00135 (elm)->field.le_prev = &(head)->lh_first; \ 00136 } 00137 00138 #define LIST_REMOVE(elm, field) { \ 00139 if ((elm)->field.le_next != NULL) \ 00140 (elm)->field.le_next->field.le_prev = \ 00141 (elm)->field.le_prev; \ 00142 *(elm)->field.le_prev = (elm)->field.le_next; \ 00143 } 00144 00145 #endif /* !_NS_BSD_LIST_H_ */