1 /* $Id: list.h,v 1.6 2006/10/31 06:25:28 gmm Exp $ */
3 * Copyright (C) 2005-2011 HighPoint Technologies, Inc.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include <dev/hptnr/hptnr_config.h>
36 #define HPT_INLINE __inline
40 struct list_head *next, *prev;
43 #define INIT_LIST_HEAD(ptr) do { (ptr)->next = (ptr); (ptr)->prev = (ptr); } while (0)
45 static HPT_INLINE void __list_add(struct list_head * _new, struct list_head * prev, struct list_head * next)
53 static HPT_INLINE void list_add(struct list_head *_new, struct list_head *head)
55 __list_add(_new, head, head->next);
58 static HPT_INLINE void list_add_tail(struct list_head *_new, struct list_head *head)
60 __list_add(_new, head->prev, head);
63 static HPT_INLINE void __list_del(struct list_head * prev, struct list_head * next)
69 static HPT_INLINE void list_del(struct list_head *entry)
71 __list_del(entry->prev, entry->next);
74 static HPT_INLINE void list_del_init(struct list_head *entry)
76 __list_del(entry->prev, entry->next);
77 INIT_LIST_HEAD(entry);
80 static HPT_INLINE int list_empty(struct list_head *head)
82 HPT_ASSERT(!(head->next==head && head->prev!=head));
83 return head->next == head;
86 static HPT_INLINE void __list_splice(struct list_head *list,
87 struct list_head *head)
89 struct list_head *first = list->next;
90 struct list_head *last = list->prev;
91 struct list_head *at = head->next;
100 static HPT_INLINE void list_splice(struct list_head *list, struct list_head *head)
102 if (!list_empty(list))
103 __list_splice(list, head);
106 static HPT_INLINE void list_splice_init(struct list_head *list, struct list_head *head)
108 if (!list_empty(list)) {
109 __list_splice(list, head);
110 INIT_LIST_HEAD(list);
114 #define list_entry(ptr, type, member) \
115 ((type *)((char *)(ptr)-(HPT_UPTR)(&((type *)0)->member)))
117 #define list_for_each(pos, head) \
118 for (pos = (head)->next; pos != (head); pos = pos->next)
120 #define list_for_each_safe(pos, n, head) \
121 for (pos = (head)->next, n = pos->next; pos != (head); \
122 pos = n, n = pos->next)
124 #define get_first_item(attached, type, member) \
125 ((type *)((char *)((attached)->next)-(HPT_UPTR)(&((type *)0)->member)))