rculfhash: make cds_lfht_iter_get_node argument const
[userspace-rcu.git] / include / urcu / rcuhlist.h
1 // SPDX-FileCopyrightText: 2002 Free Software Foundation, Inc.
2 // SPDX-FileCopyrightText: 2009 Pierre-Marc Fournier
3 // SPDX-FileCopyrightText: 2010 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 //
5 // SPDX-License-Identifier: LGPL-2.1-or-later
6
7 /*
8 * (originally part of the GNU C Library)
9 * Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
10 */
11
12 #ifndef _URCU_RCUHLIST_H
13 #define _URCU_RCUHLIST_H
14
15 #include <urcu/hlist.h>
16 #include <urcu/arch.h>
17 #include <urcu-pointer.h>
18
19 /* Add new element at the head of the list. */
20 static inline
21 void cds_hlist_add_head_rcu(struct cds_hlist_node *newp,
22 struct cds_hlist_head *head)
23 {
24 newp->next = head->next;
25 newp->prev = (struct cds_hlist_node *)head;
26 if (head->next)
27 head->next->prev = newp;
28 rcu_assign_pointer(head->next, newp);
29 }
30
31 /* Remove element from list. */
32 static inline
33 void cds_hlist_del_rcu(struct cds_hlist_node *elem)
34 {
35 if (elem->next)
36 elem->next->prev = elem->prev;
37 CMM_STORE_SHARED(elem->prev->next, elem->next);
38 }
39
40 /*
41 * Iterate through elements of the list.
42 * This must be done while rcu_read_lock() is held.
43 */
44 #define cds_hlist_for_each_rcu(pos, head) \
45 for (pos = rcu_dereference((head)->next); (pos) != NULL; \
46 pos = rcu_dereference((pos)->next))
47
48 /*
49 * cds_hlist_for_each_entry_rcu takes 4 arguments, while the Linux
50 * kernel API only takes 3.
51 * We implement cds_hlist_for_each_entry_rcu_2() to follow the Linux
52 * kernel APIs.
53 */
54 #define cds_hlist_for_each_entry_rcu(entry, pos, head, member) \
55 for (pos = rcu_dereference((head)->next), \
56 entry = cds_hlist_entry(pos, __typeof__(*(entry)), member); \
57 (pos) != NULL; \
58 pos = rcu_dereference((pos)->next), \
59 entry = cds_hlist_entry(pos, __typeof__(*(entry)), member))
60
61 #define cds_hlist_for_each_entry_rcu_2(entry, head, member) \
62 for (entry = cds_hlist_entry_safe(rcu_dereference((head)->next), \
63 __typeof__(*(entry)), member); \
64 (entry) != NULL; \
65 entry = cds_hlist_entry_safe(rcu_dereference((entry)->member.next), \
66 __typeof__(*(entry)), member))
67
68 #endif /* _URCU_RCUHLIST_H */
This page took 0.031027 seconds and 4 git commands to generate.