list.h revision 176018
190075Sobrien/* 250397Sobrien * Copyright (c) HighPoint Technologies, Inc. 3169689Skan * All rights reserved. 450397Sobrien * 590075Sobrien * Redistribution and use in source and binary forms, with or without 650397Sobrien * modification, are permitted provided that the following conditions 790075Sobrien * are met: 890075Sobrien * 1. Redistributions of source code must retain the above copyright 990075Sobrien * notice, this list of conditions and the following disclaimer. 1090075Sobrien * 2. Redistributions in binary form must reproduce the above copyright 1150397Sobrien * notice, this list of conditions and the following disclaimer in the 1290075Sobrien * documentation and/or other materials provided with the distribution. 1390075Sobrien * 1490075Sobrien * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1590075Sobrien * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1650397Sobrien * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1750397Sobrien * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1890075Sobrien * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19169689Skan * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20169689Skan * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2150397Sobrien * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2250397Sobrien * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2350397Sobrien * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2450397Sobrien * SUCH DAMAGE. 2550397Sobrien * 2650397Sobrien * $FreeBSD: head/sys/dev/hptrr/list.h 174604 2007-12-15 00:56:17Z scottl $ 2750397Sobrien */ 2850397Sobrien#include <dev/hptrr/hptrr_config.h> 2990075Sobrien/* 3090075Sobrien * $Id: list.h,v 1.6 2006/10/31 06:25:28 gmm Exp $ 3150397Sobrien * Copyright (C) 2004-2005 HighPoint Technologies, Inc. All rights reserved. 32169689Skan */ 33169689Skan#ifndef _HPT_LIST_H_ 34169689Skan#define _HPT_LIST_H_ 35169689Skan 3650397Sobrien#ifndef _LINUX_LIST_H 3750397Sobrien 3850397Sobrien#ifndef HPT_INLINE 39117395Skan#define HPT_INLINE __inline 4050397Sobrien#endif 4150397Sobrien 4250397Sobrienstruct list_head { 4350397Sobrien struct list_head *next, *prev; 4450397Sobrien}; 4550397Sobrien 4650397Sobrien#define INIT_LIST_HEAD(ptr) do { (ptr)->next = (ptr); (ptr)->prev = (ptr); } while (0) 47169689Skan 4850397Sobrienstatic HPT_INLINE void __list_add(struct list_head * _new, struct list_head * prev, struct list_head * next) 4950397Sobrien{ 5050397Sobrien next->prev = _new; 5150397Sobrien _new->next = next; 5250397Sobrien _new->prev = prev; 5350397Sobrien prev->next = _new; 5450397Sobrien} 5550397Sobrien 5652284Sobrienstatic HPT_INLINE void list_add(struct list_head *_new, struct list_head *head) 5790075Sobrien{ 5852284Sobrien __list_add(_new, head, head->next); 5952284Sobrien} 6052284Sobrien 6152284Sobrienstatic HPT_INLINE void list_add_tail(struct list_head *_new, struct list_head *head) 62169689Skan{ 63169689Skan __list_add(_new, head->prev, head); 64169689Skan} 6550397Sobrien 6650397Sobrienstatic HPT_INLINE void __list_del(struct list_head * prev, struct list_head * next) 6750397Sobrien{ 6850397Sobrien next->prev = prev; 6950397Sobrien prev->next = next; 7050397Sobrien} 7150397Sobrien 7250397Sobrienstatic HPT_INLINE void list_del(struct list_head *entry) 7350397Sobrien{ 7450397Sobrien __list_del(entry->prev, entry->next); 7550397Sobrien} 7650397Sobrien 7750397Sobrienstatic HPT_INLINE void list_del_init(struct list_head *entry) 7850397Sobrien{ 7950397Sobrien __list_del(entry->prev, entry->next); 80169689Skan INIT_LIST_HEAD(entry); 81169689Skan} 82169689Skan 83169689Skanstatic HPT_INLINE int list_empty(struct list_head *head) 8450397Sobrien{ 8550397Sobrien HPT_ASSERT(!(head->next==head && head->prev!=head)); 8650397Sobrien return head->next == head; 8750397Sobrien} 88169689Skan 89169689Skanstatic HPT_INLINE void __list_splice(struct list_head *list, 90169689Skan struct list_head *head) 9150397Sobrien{ 9250397Sobrien struct list_head *first = list->next; 9350397Sobrien struct list_head *last = list->prev; 9450397Sobrien struct list_head *at = head->next; 9590075Sobrien 96169689Skan first->prev = head; 97169689Skan head->next = first; 98169689Skan 9950397Sobrien last->next = at; 100169689Skan at->prev = last; 101169689Skan} 10250397Sobrien 10350397Sobrienstatic HPT_INLINE void list_splice(struct list_head *list, struct list_head *head) 10450397Sobrien{ 10550397Sobrien if (!list_empty(list)) 10650397Sobrien __list_splice(list, head); 10790075Sobrien} 10850397Sobrien 10950397Sobrienstatic HPT_INLINE void list_splice_init(struct list_head *list, struct list_head *head) 11050397Sobrien{ 11150397Sobrien if (!list_empty(list)) { 11250397Sobrien __list_splice(list, head); 11350397Sobrien INIT_LIST_HEAD(list); 11450397Sobrien } 11550397Sobrien} 11690075Sobrien 11750397Sobrien#define list_entry(ptr, type, member) \ 11850397Sobrien ((type *)((char *)(ptr)-(HPT_UPTR)(&((type *)0)->member))) 11950397Sobrien 12050397Sobrien#define list_for_each(pos, head) \ 121169689Skan for (pos = (head)->next; pos != (head); pos = pos->next) 122169689Skan 123169689Skan#define list_for_each_safe(pos, n, head) \ 124169689Skan for (pos = (head)->next, n = pos->next; pos != (head); \ 12590075Sobrien pos = n, n = pos->next) 126 127#define get_first_item(attached, type, member) \ 128 ((type *)((char *)((attached)->next)-(HPT_UPTR)(&((type *)0)->member))) 129 130#endif 131 132#endif 133