uatomic/x86: Remove redundant memory barriers
[urcu.git] / include / urcu / rculist.h
1 // SPDX-FileCopyrightText: 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_RCULIST_H
13 #define _URCU_RCULIST_H
14
15 #include <urcu/list.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_list_add_rcu(struct cds_list_head *newp, struct cds_list_head *head)
22 {
23 newp->next = head->next;
24 newp->prev = head;
25 head->next->prev = newp;
26 rcu_assign_pointer(head->next, newp);
27 }
28
29 /* Add new element at the tail of the list. */
30 static inline
31 void cds_list_add_tail_rcu(struct cds_list_head *newp,
32 struct cds_list_head *head)
33 {
34 newp->next = head;
35 newp->prev = head->prev;
36 rcu_assign_pointer(head->prev->next, newp);
37 head->prev = newp;
38 }
39
40 /*
41 * Replace an old entry atomically with respect to concurrent RCU
42 * traversal. Mutual exclusion against concurrent updates is required
43 * though.
44 */
45 static inline
46 void cds_list_replace_rcu(struct cds_list_head *old, struct cds_list_head *_new)
47 {
48 _new->next = old->next;
49 _new->prev = old->prev;
50 rcu_assign_pointer(_new->prev->next, _new);
51 _new->next->prev = _new;
52 }
53
54 /* Remove element from list. */
55 static inline
56 void cds_list_del_rcu(struct cds_list_head *elem)
57 {
58 elem->next->prev = elem->prev;
59 CMM_STORE_SHARED(elem->prev->next, elem->next);
60 }
61
62 /*
63 * Iteration through all elements of the list must be done while rcu_read_lock()
64 * is held.
65 */
66
67 /* Iterate forward over the elements of the list. */
68 #define cds_list_for_each_rcu(pos, head) \
69 for (pos = rcu_dereference((head)->next); (pos) != (head); \
70 pos = rcu_dereference((pos)->next))
71
72 /* Iterate through elements of the list. */
73 #define cds_list_for_each_entry_rcu(pos, head, member) \
74 for (pos = cds_list_entry(rcu_dereference((head)->next), __typeof__(*(pos)), member); \
75 &(pos)->member != (head); \
76 pos = cds_list_entry(rcu_dereference((pos)->member.next), __typeof__(*(pos)), member))
77
78 #endif /* _URCU_RCULIST_H */
This page took 0.031616 seconds and 5 git commands to generate.