1 /* Copyright (C) 2002, 2009, 2011 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
26 /* The definitions of this file are adopted from those which can be
27 found in the Linux kernel headers to enable people familiar with
28 the latter find their way in these sources as well. */
31 #if defined __need_list_t || defined _LIST_H
32 # ifndef __list_t_defined
33 # define __list_t_defined
34 /* Basic type for the double-link list. */
35 typedef struct list_head
37 struct list_head
*next
;
38 struct list_head
*prev
;
48 /* Define a variable with the head and tail of the list. */
49 # define LIST_HEAD(name) \
50 list_t name = { &(name), &(name) }
52 /* Initialize a new list head. */
53 # define INIT_LIST_HEAD(ptr) \
54 (ptr)->next = (ptr)->prev = (ptr)
57 /* Add new element at the head of the list. */
59 list_add (list_t
*newp
, list_t
*head
)
61 newp
->next
= head
->next
;
63 head
->next
->prev
= newp
;
64 atomic_write_barrier ();
69 /* Remove element from list. */
71 list_del (list_t
*elem
)
73 elem
->next
->prev
= elem
->prev
;
74 elem
->prev
->next
= elem
->next
;
80 list_splice (list_t
*add
, list_t
*head
)
82 /* Do nothing if the list which gets added is empty. */
85 add
->next
->prev
= head
;
86 add
->prev
->next
= head
->next
;
87 head
->next
->prev
= add
->prev
;
88 head
->next
= add
->next
;
93 /* Get typed element from list at a given position. */
94 # define list_entry(ptr, type, member) \
95 ((type *) ((char *) (ptr) - (unsigned long) (&((type *) 0)->member)))
99 /* Iterate forward over the elements of the list. */
100 # define list_for_each(pos, head) \
101 for (pos = (head)->next; pos != (head); pos = pos->next)
104 /* Iterate forward over the elements of the list. */
105 # define list_for_each_prev(pos, head) \
106 for (pos = (head)->prev; pos != (head); pos = pos->prev)
109 /* Iterate backwards over the elements list. The list elements can be
110 removed from the list while doing this. */
111 # define list_for_each_prev_safe(pos, p, head) \
112 for (pos = (head)->prev, p = pos->prev; \
114 pos = p, p = pos->prev)