rculist: implement cds_list_add_tail_rcu
[urcu.git] / urcu / rculist.h
1 /*
2 * Copyright (C) 2002 Free Software Foundation, Inc.
3 * (originally part of the GNU C Library)
4 * Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
5 *
6 * Copyright (C) 2009 Pierre-Marc Fournier
7 * Conversion to RCU list.
8 * Copyright (C) 2010 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
9 *
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
14 *
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 */
24
25 #ifndef _URCU_RCULIST_H
26 #define _URCU_RCULIST_H
27
28 #include <urcu/list.h>
29 #include <urcu/arch.h>
30 #include <urcu-pointer.h>
31
32 /* Add new element at the head of the list. */
33 static inline
34 void cds_list_add_rcu(struct cds_list_head *newp, struct cds_list_head *head)
35 {
36 newp->next = head->next;
37 newp->prev = head;
38 cmm_smp_wmb();
39 head->next->prev = newp;
40 head->next = newp;
41 }
42
43 /* Add new element at the tail of the list. */
44 static inline
45 void cds_list_add_tail_rcu(struct cds_list_head *newp,
46 struct cds_list_head *head)
47 {
48 newp->next = head;
49 newp->prev = head->prev;
50 rcu_assign_pointer(head->prev->next, newp);
51 head->prev = newp;
52 }
53
54 /*
55 * Replace an old entry atomically with respect to concurrent RCU
56 * traversal. Mutual exclusion against concurrent updates is required
57 * though.
58 */
59 static inline
60 void cds_list_replace_rcu(struct cds_list_head *old, struct cds_list_head *_new)
61 {
62 _new->next = old->next;
63 _new->prev = old->prev;
64 rcu_assign_pointer(_new->prev->next, _new);
65 _new->next->prev = _new;
66 }
67
68 /* Remove element from list. */
69 static inline
70 void cds_list_del_rcu(struct cds_list_head *elem)
71 {
72 elem->next->prev = elem->prev;
73 elem->prev->next = elem->next;
74 }
75
76 /*
77 * Iteration through all elements of the list must be done while rcu_read_lock()
78 * is held.
79 */
80
81 /* Iterate forward over the elements of the list. */
82 #define cds_list_for_each_rcu(pos, head) \
83 for (pos = rcu_dereference((head)->next); pos != (head); \
84 pos = rcu_dereference(pos->next))
85
86
87 /* Iterate through elements of the list. */
88 #define cds_list_for_each_entry_rcu(pos, head, member) \
89 for (pos = cds_list_entry(rcu_dereference((head)->next), __typeof__(*pos), member); \
90 &pos->member != (head); \
91 pos = cds_list_entry(rcu_dereference(pos->member.next), __typeof__(*pos), member))
92
93 #endif /* _URCU_RCULIST_H */
This page took 0.03164 seconds and 5 git commands to generate.