ldbl-128ibm: Automatic replacing of _Float128 and L()
[glibc.git] / include / list.h
blobdec5deef8e04127ef842428346b4898821028a81
1 /* Copyright (C) 2002-2017 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, see
17 <http://www.gnu.org/licenses/>. */
19 #ifndef _LIST_H
20 #define _LIST_H 1
22 /* Internal: doubly linked lists. */
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. */
28 #include <list_t.h>
29 #include <atomic.h>
31 /* Define a variable with the head and tail of the list. */
32 #define LIST_HEAD(name) \
33 list_t name = { &(name), &(name) }
35 /* Initialize a new list head. */
36 #define INIT_LIST_HEAD(ptr) \
37 (ptr)->next = (ptr)->prev = (ptr)
40 /* Add new element at the head of the list. */
41 static inline void
42 list_add (list_t *newp, list_t *head)
44 newp->next = head->next;
45 newp->prev = head;
46 head->next->prev = newp;
47 atomic_write_barrier ();
48 head->next = newp;
52 /* Remove element from list. */
53 static inline void
54 list_del (list_t *elem)
56 elem->next->prev = elem->prev;
57 elem->prev->next = elem->next;
61 /* Join two lists. */
62 static inline void
63 list_splice (list_t *add, list_t *head)
65 /* Do nothing if the list which gets added is empty. */
66 if (add != add->next)
68 add->next->prev = head;
69 add->prev->next = head->next;
70 head->next->prev = add->prev;
71 head->next = add->next;
76 /* Get typed element from list at a given position. */
77 #define list_entry(ptr, type, member) \
78 ((type *) ((char *) (ptr) - (unsigned long) (&((type *) 0)->member)))
82 /* Iterate forward over the elements of the list. */
83 #define list_for_each(pos, head) \
84 for (pos = (head)->next; pos != (head); pos = pos->next)
87 /* Iterate forward over the elements of the list. */
88 #define list_for_each_prev(pos, head) \
89 for (pos = (head)->prev; pos != (head); pos = pos->prev)
92 /* Iterate backwards over the elements list. The list elements can be
93 removed from the list while doing this. */
94 #define list_for_each_prev_safe(pos, p, head) \
95 for (pos = (head)->prev, p = pos->prev; \
96 pos != (head); \
97 pos = p, p = pos->prev)
99 #endif /* list.h */