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 | */ | |
5db941e8 MD |
24 | |
25 | #ifndef _URCU_RCUHLIST_H | |
26 | #define _URCU_RCUHLIST_H | |
27 | ||
28 | #include <urcu/hlist.h> | |
29 | #include <urcu/arch.h> | |
30 | #include <urcu-pointer.h> | |
31 | ||
32 | /* Add new element at the head of the list. | |
33 | */ | |
16aa9ee8 DG |
34 | static inline void cds_hlist_add_head_rcu(struct cds_hlist_node *newp, |
35 | struct cds_hlist_head *head) | |
5db941e8 MD |
36 | { |
37 | newp->next = head->next; | |
16aa9ee8 | 38 | newp->prev = (struct cds_hlist_node *)head; |
5481ddb3 | 39 | cmm_smp_wmb(); |
5db941e8 MD |
40 | if (head->next) |
41 | head->next->prev = newp; | |
42 | head->next = newp; | |
43 | } | |
44 | ||
45 | /* Remove element from list. */ | |
16aa9ee8 | 46 | static inline void cds_hlist_del_rcu(struct cds_hlist_node *elem) |
5db941e8 MD |
47 | { |
48 | if (elem->next) | |
49 | elem->next->prev = elem->prev; | |
50 | elem->prev->next = elem->next; | |
51 | } | |
52 | ||
9e562872 MD |
53 | /* |
54 | * Get first element from a RCU hlist. Assumes the hlist is not empty. | |
55 | * This must be done while rcu_read_lock() is held. | |
56 | */ | |
d95cdcb8 | 57 | #define cds_hlist_first_rcu(ptr, type) \ |
9e562872 MD |
58 | rcu_dereference((ptr)->next) |
59 | ||
df65c98a MD |
60 | /* |
61 | * Get first entry from a RCU hlist. Assumes the hlist is not empty. | |
62 | * This must be done while rcu_read_lock() is held. | |
63 | */ | |
9e562872 | 64 | #define cds_hlist_first_entry_rcu(ptr, type, member) \ |
df65c98a | 65 | cds_hlist_entry(rcu_dereference((ptr)->next), type, member) |
5db941e8 | 66 | |
9e562872 MD |
67 | /* |
68 | * Iterate through nodes of the list. | |
69 | * This must be done while rcu_read_lock() is held. | |
70 | */ | |
71 | ||
d95cdcb8 | 72 | #define cds_hlist_for_each_rcu(pos, head) \ |
9e562872 MD |
73 | for (pos = rcu_dereference((head)->next); \ |
74 | pos != NULL; \ | |
d95cdcb8 | 75 | pos = rcu_dereference((pos)->next)) |
9e562872 MD |
76 | |
77 | /* | |
78 | * Iterate through elements of the list. | |
5db941e8 MD |
79 | * This must be done while rcu_read_lock() is held. |
80 | */ | |
81 | ||
16aa9ee8 | 82 | #define cds_hlist_for_each_entry_rcu(entry, pos, head, member) \ |
5db941e8 | 83 | for (pos = rcu_dereference((head)->next), \ |
bdffa73a | 84 | entry = cds_hlist_entry(pos, __typeof__(*entry), member); \ |
5db941e8 MD |
85 | pos != NULL; \ |
86 | pos = rcu_dereference(pos->next), \ | |
bdffa73a | 87 | entry = cds_hlist_entry(pos, __typeof__(*entry), member)) |
5db941e8 MD |
88 | |
89 | #endif /* _URCU_RCUHLIST_H */ |