Use GMP 6.3.0, MPFR 4.2.1 in build-many-glibcs.py
[glibc.git] / include / list.h
blobc4e36c6f6541a5ec2e777a4033847c127c3285ec
1 /* Copyright (C) 2002-2023 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
18 #ifndef _LIST_H
19 #define _LIST_H 1
21 /* Internal: doubly linked lists. */
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. */
27 #include <list_t.h>
28 #include <atomic.h>
30 /* Define a variable with the head and tail of the list. */
31 #define LIST_HEAD(name) \
32 list_t name = { &(name), &(name) }
34 /* Initialize a new list head. */
35 #define INIT_LIST_HEAD(ptr) \
36 (ptr)->next = (ptr)->prev = (ptr)
39 /* Add new element at the head of the list. */
40 static inline void
41 list_add (list_t *newp, list_t *head)
43 newp->next = head->next;
44 newp->prev = head;
45 head->next->prev = newp;
46 atomic_write_barrier ();
47 head->next = newp;
51 /* Remove element from list. */
52 static inline void
53 list_del (list_t *elem)
55 elem->next->prev = elem->prev;
56 elem->prev->next = elem->next;
60 /* Join two lists. */
61 static inline void
62 list_splice (list_t *add, list_t *head)
64 /* Do nothing if the list which gets added is empty. */
65 if (add != add->next)
67 add->next->prev = head;
68 add->prev->next = head->next;
69 head->next->prev = add->prev;
70 head->next = add->next;
75 /* Get typed element from list at a given position. */
76 #define list_entry(ptr, type, member) \
77 ((type *) ((char *) (ptr) - (unsigned long) (&((type *) 0)->member)))
81 /* Iterate forward over the elements of the list. */
82 #define list_for_each(pos, head) \
83 for (pos = (head)->next; pos != (head); pos = pos->next)
86 /* Iterate forward over the elements of the list. */
87 #define list_for_each_prev(pos, head) \
88 for (pos = (head)->prev; pos != (head); pos = pos->prev)
91 /* Iterate backwards over the elements list. The list elements can be
92 removed from the list while doing this. */
93 #define list_for_each_prev_safe(pos, p, head) \
94 for (pos = (head)->prev, p = pos->prev; \
95 pos != (head); \
96 pos = p, p = pos->prev)
98 #endif /* list.h */