1 // SPDX-FileCopyrightText: Free Software Foundation, Inc.
2 // SPDX-FileCopyrightText: 2009 Pierre-Marc Fournier
3 // SPDX-FileCopyrightText: 2010 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 // SPDX-License-Identifier: LGPL-2.1-or-later
8 * (originally part of the GNU C Library)
9 * Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
12 #ifndef _URCU_RCULIST_H
13 #define _URCU_RCULIST_H
15 #include <urcu/list.h>
16 #include <urcu/arch.h>
17 #include <urcu-pointer.h>
19 /* Add new element at the head of the list. */
21 void cds_list_add_rcu(struct cds_list_head
*newp
, struct cds_list_head
*head
)
23 newp
->next
= head
->next
;
25 head
->next
->prev
= newp
;
26 rcu_assign_pointer(head
->next
, newp
);
29 /* Add new element at the tail of the list. */
31 void cds_list_add_tail_rcu(struct cds_list_head
*newp
,
32 struct cds_list_head
*head
)
35 newp
->prev
= head
->prev
;
36 rcu_assign_pointer(head
->prev
->next
, newp
);
41 * Replace an old entry atomically with respect to concurrent RCU
42 * traversal. Mutual exclusion against concurrent updates is required
46 void cds_list_replace_rcu(struct cds_list_head
*old
, struct cds_list_head
*_new
)
48 _new
->next
= old
->next
;
49 _new
->prev
= old
->prev
;
50 rcu_assign_pointer(_new
->prev
->next
, _new
);
51 _new
->next
->prev
= _new
;
54 /* Remove element from list. */
56 void cds_list_del_rcu(struct cds_list_head
*elem
)
58 elem
->next
->prev
= elem
->prev
;
59 CMM_STORE_SHARED(elem
->prev
->next
, elem
->next
);
63 * Iteration through all elements of the list must be done while rcu_read_lock()
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))
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))
78 #endif /* _URCU_RCULIST_H */
This page took 0.030832 seconds and 4 git commands to generate.