1 /* Copyright (C) 2002 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
23 /* The definitions of this file are adopted from those which can be
24 found in the Linux kernel headers to enable people familiar with
25 the latter find their way in these sources as well. */
28 /* Basic type for the double-link list. */
31 struct cds_list_head
*next
;
32 struct cds_list_head
*prev
;
36 /* Define a variable with the head and tail of the list. */
37 #define CDS_LIST_HEAD(name) \
38 struct cds_list_head name = { &(name), &(name) }
40 /* Initialize a new list head. */
41 #define CDS_INIT_LIST_HEAD(ptr) \
42 (ptr)->next = (ptr)->prev = (ptr)
44 #define CDS_LIST_HEAD_INIT(name) { .prev = &(name), .next = &(name) }
46 /* Add new element at the head of the list. */
48 cds_list_add (struct cds_list_head
*newp
, struct cds_list_head
*head
)
50 head
->next
->prev
= newp
;
51 newp
->next
= head
->next
;
57 /* Add new element at the tail of the list. */
59 cds_list_add_tail (struct cds_list_head
*newp
, struct cds_list_head
*head
)
61 head
->prev
->next
= newp
;
63 newp
->prev
= head
->prev
;
68 /* Remove element from list. */
70 __cds_list_del (struct cds_list_head
*prev
, struct cds_list_head
*next
)
76 /* Remove element from list. */
78 cds_list_del (struct cds_list_head
*elem
)
80 __cds_list_del (elem
->prev
, elem
->next
);
83 /* delete from list, add to another list as head */
85 cds_list_move (struct cds_list_head
*elem
, struct cds_list_head
*head
)
87 __cds_list_del (elem
->prev
, elem
->next
);
88 cds_list_add (elem
, head
);
91 /* replace an old entry.
94 cds_list_replace(struct cds_list_head
*old
, struct cds_list_head
*_new
)
96 _new
->next
= old
->next
;
97 _new
->prev
= old
->prev
;
98 _new
->prev
->next
= _new
;
99 _new
->next
->prev
= _new
;
102 /* Join two lists. */
104 cds_list_splice (struct cds_list_head
*add
, struct cds_list_head
*head
)
106 /* Do nothing if the list which gets added is empty. */
107 if (add
!= add
->next
)
109 add
->next
->prev
= head
;
110 add
->prev
->next
= head
->next
;
111 head
->next
->prev
= add
->prev
;
112 head
->next
= add
->next
;
117 /* Get typed element from list at a given position. */
118 #define cds_list_entry(ptr, type, member) \
119 ((type *) ((char *) (ptr) - (unsigned long) (&((type *) 0)->member)))
123 /* Iterate forward over the elements of the list. */
124 #define cds_list_for_each(pos, head) \
125 for (pos = (head)->next; pos != (head); pos = pos->next)
128 /* Iterate forward over the elements of the list. */
129 #define cds_list_for_each_prev(pos, head) \
130 for (pos = (head)->prev; pos != (head); pos = pos->prev)
133 /* Iterate backwards over the elements list. The list elements can be
134 removed from the list while doing this. */
135 #define cds_list_for_each_prev_safe(pos, p, head) \
136 for (pos = (head)->prev, p = pos->prev; \
138 pos = p, p = pos->prev)
140 #define cds_list_for_each_entry(pos, head, member) \
141 for (pos = cds_list_entry((head)->next, typeof(*pos), member); \
142 &pos->member != (head); \
143 pos = cds_list_entry(pos->member.next, typeof(*pos), member))
145 #define cds_list_for_each_entry_reverse(pos, head, member) \
146 for (pos = cds_list_entry((head)->prev, typeof(*pos), member); \
147 &pos->member != (head); \
148 pos = cds_list_entry(pos->member.prev, typeof(*pos), member))
150 #define cds_list_for_each_entry_safe(pos, p, head, member) \
151 for (pos = cds_list_entry((head)->next, typeof(*pos), member), \
152 p = cds_list_entry(pos->member.next,typeof(*pos), member); \
153 &pos->member != (head); \
154 pos = p, p = cds_list_entry(pos->member.next, typeof(*pos), member))
156 static inline int cds_list_empty(struct cds_list_head
*head
)
158 return head
== head
->next
;
161 static inline void cds_list_replace_init(struct cds_list_head
*old
,
162 struct cds_list_head
*_new
)
164 struct cds_list_head
*head
= old
->next
;
166 cds_list_add_tail(_new
, head
);
167 CDS_INIT_LIST_HEAD(old
);
170 #endif /* _CDS_LIST_H */
This page took 0.033517 seconds and 4 git commands to generate.