Commit | Line | Data |
---|---|---|
a00718e7 MD |
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 | */ | |
7a50dcf7 | 24 | |
63ff4873 MD |
25 | #ifndef _URCU_RCULIST_H |
26 | #define _URCU_RCULIST_H | |
27 | ||
28 | #include <urcu/list.h> | |
3cd243cb MD |
29 | #include <urcu/arch.h> |
30 | #include <urcu-pointer.h> | |
7a50dcf7 | 31 | |
e6decba5 MD |
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) | |
7a50dcf7 | 35 | { |
4b677847 MD |
36 | struct cds_list_head *first = head->next; |
37 | ||
38 | newp->next = first; | |
63ff4873 | 39 | newp->prev = head; |
63ff4873 | 40 | head->next->prev = newp; |
4b677847 | 41 | rcu_assign_pointer(head->next, newp); |
7a50dcf7 MD |
42 | } |
43 | ||
e2fcb2d3 MD |
44 | /* Add new element at the tail of the list. */ |
45 | static inline | |
46 | void cds_list_add_tail_rcu(struct cds_list_head *newp, | |
47 | struct cds_list_head *head) | |
48 | { | |
49 | newp->next = head; | |
50 | newp->prev = head->prev; | |
51 | rcu_assign_pointer(head->prev->next, newp); | |
52 | head->prev = newp; | |
53 | } | |
54 | ||
e6decba5 MD |
55 | /* |
56 | * Replace an old entry atomically with respect to concurrent RCU | |
57 | * traversal. Mutual exclusion against concurrent updates is required | |
58 | * though. | |
5db941e8 | 59 | */ |
e6decba5 MD |
60 | static inline |
61 | void cds_list_replace_rcu(struct cds_list_head *old, struct cds_list_head *_new) | |
5db941e8 MD |
62 | { |
63 | _new->next = old->next; | |
64 | _new->prev = old->prev; | |
65 | rcu_assign_pointer(_new->prev->next, _new); | |
66 | _new->next->prev = _new; | |
67 | } | |
7a50dcf7 | 68 | |
63ff4873 | 69 | /* Remove element from list. */ |
e6decba5 MD |
70 | static inline |
71 | void cds_list_del_rcu(struct cds_list_head *elem) | |
7a50dcf7 | 72 | { |
63ff4873 | 73 | elem->next->prev = elem->prev; |
4b677847 | 74 | CMM_STORE_SHARED(elem->prev->next, elem->next); |
7a50dcf7 MD |
75 | } |
76 | ||
5db941e8 MD |
77 | /* |
78 | * Iteration through all elements of the list must be done while rcu_read_lock() | |
79 | * is held. | |
80 | */ | |
81 | ||
82 | /* Iterate forward over the elements of the list. */ | |
16aa9ee8 | 83 | #define cds_list_for_each_rcu(pos, head) \ |
e6decba5 MD |
84 | for (pos = rcu_dereference((head)->next); pos != (head); \ |
85 | pos = rcu_dereference(pos->next)) | |
5db941e8 | 86 | |
7a50dcf7 | 87 | |
e6decba5 MD |
88 | /* Iterate through elements of the list. */ |
89 | #define cds_list_for_each_entry_rcu(pos, head, member) \ | |
90 | for (pos = cds_list_entry(rcu_dereference((head)->next), __typeof__(*pos), member); \ | |
91 | &pos->member != (head); \ | |
92 | pos = cds_list_entry(rcu_dereference(pos->member.next), __typeof__(*pos), member)) | |
7a50dcf7 | 93 | |
63ff4873 | 94 | #endif /* _URCU_RCULIST_H */ |