uatomic/x86: Remove redundant memory barriers
[urcu.git] / include / urcu / rculist.h
CommitLineData
d3d3857f
MJ
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
a00718e7 7/*
a00718e7
MD
8 * (originally part of the GNU C Library)
9 * Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
a00718e7 10 */
7a50dcf7 11
63ff4873
MD
12#ifndef _URCU_RCULIST_H
13#define _URCU_RCULIST_H
14
15#include <urcu/list.h>
3cd243cb
MD
16#include <urcu/arch.h>
17#include <urcu-pointer.h>
7a50dcf7 18
e6decba5
MD
19/* Add new element at the head of the list. */
20static inline
21void cds_list_add_rcu(struct cds_list_head *newp, struct cds_list_head *head)
7a50dcf7 22{
63ff4873
MD
23 newp->next = head->next;
24 newp->prev = head;
63ff4873 25 head->next->prev = newp;
db757a4e 26 rcu_assign_pointer(head->next, newp);
7a50dcf7
MD
27}
28
e2fcb2d3
MD
29/* Add new element at the tail of the list. */
30static inline
31void 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
e6decba5
MD
40/*
41 * Replace an old entry atomically with respect to concurrent RCU
42 * traversal. Mutual exclusion against concurrent updates is required
43 * though.
5db941e8 44 */
e6decba5
MD
45static inline
46void cds_list_replace_rcu(struct cds_list_head *old, struct cds_list_head *_new)
5db941e8
MD
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}
7a50dcf7 53
63ff4873 54/* Remove element from list. */
e6decba5
MD
55static inline
56void cds_list_del_rcu(struct cds_list_head *elem)
7a50dcf7 57{
63ff4873 58 elem->next->prev = elem->prev;
db757a4e 59 CMM_STORE_SHARED(elem->prev->next, elem->next);
7a50dcf7
MD
60}
61
5db941e8
MD
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. */
16aa9ee8 68#define cds_list_for_each_rcu(pos, head) \
5e1b7c84
MD
69 for (pos = rcu_dereference((head)->next); (pos) != (head); \
70 pos = rcu_dereference((pos)->next))
7a50dcf7 71
e6decba5
MD
72/* Iterate through elements of the list. */
73#define cds_list_for_each_entry_rcu(pos, head, member) \
5e1b7c84
MD
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))
7a50dcf7 77
63ff4873 78#endif /* _URCU_RCULIST_H */
This page took 0.05103 seconds and 4 git commands to generate.