48d9bbb9c1b75e6d7024dab59f7ea56179972d19
2 * Copyright (C) 2002 Free Software Foundation, Inc.
3 * This file is part of the GNU C Library.
4 * Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; only
9 * version 2.1 of the License.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 /* The definitions of this file are adopted from those which can be
25 found in the Linux kernel headers to enable people familiar with
26 the latter find their way in these sources as well. */
32 /* Basic type for the double-link list. */
35 struct bt_list_head
*next
;
36 struct bt_list_head
*prev
;
40 /* Define a variable with the head and tail of the list. */
41 #define BT_LIST_HEAD(name) \
42 struct bt_list_head name = { &(name), &(name) }
44 /* Initialize a new list head. */
45 #define BT_INIT_LIST_HEAD(ptr) \
46 (ptr)->next = (ptr)->prev = (ptr)
48 #define BT_LIST_HEAD_INIT(name) { .prev = &(name), .next = &(name) }
50 /* Add new element at the head of the list. */
52 bt_list_add (struct bt_list_head
*newp
, struct bt_list_head
*head
)
54 head
->next
->prev
= newp
;
55 newp
->next
= head
->next
;
61 /* Add new element at the tail of the list. */
63 bt_list_add_tail (struct bt_list_head
*newp
, struct bt_list_head
*head
)
65 head
->prev
->next
= newp
;
67 newp
->prev
= head
->prev
;
72 /* Remove element from list. */
74 __bt_list_del (struct bt_list_head
*prev
, struct bt_list_head
*next
)
80 /* Remove element from list. */
82 bt_list_del (struct bt_list_head
*elem
)
84 __bt_list_del (elem
->prev
, elem
->next
);
87 /* delete from list, add to another list as head */
89 bt_list_move (struct bt_list_head
*elem
, struct bt_list_head
*head
)
91 __bt_list_del (elem
->prev
, elem
->next
);
92 bt_list_add (elem
, head
);
95 /* replace an old entry.
98 bt_list_replace(struct bt_list_head
*old
, struct bt_list_head
*_new
)
100 _new
->next
= old
->next
;
101 _new
->prev
= old
->prev
;
102 _new
->prev
->next
= _new
;
103 _new
->next
->prev
= _new
;
106 /* Join two lists. */
108 bt_list_splice (struct bt_list_head
*add
, struct bt_list_head
*head
)
110 /* Do nothing if the list which gets added is empty. */
111 if (add
!= add
->next
)
113 add
->next
->prev
= head
;
114 add
->prev
->next
= head
->next
;
115 head
->next
->prev
= add
->prev
;
116 head
->next
= add
->next
;
121 /* Get typed element from list at a given position. */
122 #define bt_list_entry(ptr, type, member) \
123 ((type *) ((char *) (ptr) - (uintptr_t) (&((type *) 0)->member)))
127 /* Iterate forward over the elements of the list. */
128 #define bt_list_for_each(pos, head) \
129 for (pos = (head)->next; pos != (head); pos = pos->next)
132 /* Iterate forward over the elements of the list. */
133 #define bt_list_for_each_prev(pos, head) \
134 for (pos = (head)->prev; pos != (head); pos = pos->prev)
137 /* Iterate backwards over the elements list. The list elements can be
138 removed from the list while doing this. */
139 #define bt_list_for_each_prev_safe(pos, p, head) \
140 for (pos = (head)->prev, p = pos->prev; \
142 pos = p, p = pos->prev)
144 #define bt_list_for_each_entry(pos, head, member) \
145 for (pos = bt_list_entry((head)->next, typeof(*pos), member); \
146 &pos->member != (head); \
147 pos = bt_list_entry(pos->member.next, typeof(*pos), member))
149 #define bt_list_for_each_entry_reverse(pos, head, member) \
150 for (pos = bt_list_entry((head)->prev, typeof(*pos), member); \
151 &pos->member != (head); \
152 pos = bt_list_entry(pos->member.prev, typeof(*pos), member))
154 #define bt_list_for_each_entry_safe(pos, p, head, member) \
155 for (pos = bt_list_entry((head)->next, typeof(*pos), member), \
156 p = bt_list_entry(pos->member.next,typeof(*pos), member); \
157 &pos->member != (head); \
158 pos = p, p = bt_list_entry(pos->member.next, typeof(*pos), member))
160 static inline int bt_list_empty(struct bt_list_head
*head
)
162 return head
== head
->next
;
165 static inline void bt_list_replace_init(struct bt_list_head
*old
,
166 struct bt_list_head
*_new
)
168 struct bt_list_head
*head
= old
->next
;
170 bt_list_add_tail(_new
, head
);
171 BT_INIT_LIST_HEAD(old
);
178 #endif /* _BT_LIST_H */
This page took 0.035293 seconds and 3 git commands to generate.