Commit | Line | Data |
---|---|---|
63ff4873 MD |
1 | /* Copyright (C) 2002 Free Software Foundation, Inc. |
2 | This file is part of the GNU C Library. | |
3 | Contributed by Ulrich Drepper <drepper@redhat.com>, 2002. | |
7a50dcf7 | 4 | |
63ff4873 MD |
5 | Copyright (C) 2009 Pierre-Marc Fournier |
6 | Conversion to RCU list. | |
5db941e8 | 7 | Copyright (C) 2010 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
63ff4873 MD |
8 | |
9 | The GNU C Library is free software; you can redistribute it and/or | |
10 | modify it under the terms of the GNU Lesser General Public | |
11 | License as published by the Free Software Foundation; either | |
12 | version 2.1 of the License, or (at your option) any later version. | |
13 | ||
14 | The GNU C Library is distributed in the hope that it will be useful, | |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
17 | Lesser General Public License for more details. | |
18 | ||
19 | You should have received a copy of the GNU Lesser General Public | |
20 | License along with the GNU C Library; if not, write to the Free | |
21 | Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | |
22 | 02111-1307 USA. */ | |
7a50dcf7 | 23 | |
63ff4873 MD |
24 | #ifndef _URCU_RCULIST_H |
25 | #define _URCU_RCULIST_H | |
26 | ||
27 | #include <urcu/list.h> | |
3cd243cb MD |
28 | #include <urcu/arch.h> |
29 | #include <urcu-pointer.h> | |
7a50dcf7 | 30 | |
63ff4873 | 31 | /* Add new element at the head of the list. |
7a50dcf7 | 32 | */ |
16aa9ee8 | 33 | static inline void cds_list_add_rcu(list_t *newp, list_t *head) |
7a50dcf7 | 34 | { |
63ff4873 MD |
35 | newp->next = head->next; |
36 | newp->prev = head; | |
5481ddb3 | 37 | cmm_smp_wmb(); |
63ff4873 MD |
38 | head->next->prev = newp; |
39 | head->next = newp; | |
7a50dcf7 MD |
40 | } |
41 | ||
5db941e8 MD |
42 | /* replace an old entry atomically. |
43 | */ | |
16aa9ee8 | 44 | static inline void cds_list_replace_rcu(list_t *old, list_t *_new) |
5db941e8 MD |
45 | { |
46 | _new->next = old->next; | |
47 | _new->prev = old->prev; | |
48 | rcu_assign_pointer(_new->prev->next, _new); | |
49 | _new->next->prev = _new; | |
50 | } | |
7a50dcf7 | 51 | |
63ff4873 | 52 | /* Remove element from list. */ |
16aa9ee8 | 53 | static inline void cds_list_del_rcu(list_t *elem) |
7a50dcf7 | 54 | { |
63ff4873 MD |
55 | elem->next->prev = elem->prev; |
56 | elem->prev->next = elem->next; | |
7a50dcf7 MD |
57 | } |
58 | ||
5db941e8 MD |
59 | /* |
60 | * Iteration through all elements of the list must be done while rcu_read_lock() | |
61 | * is held. | |
62 | */ | |
63 | ||
64 | /* Iterate forward over the elements of the list. */ | |
16aa9ee8 | 65 | #define cds_list_for_each_rcu(pos, head) \ |
5db941e8 MD |
66 | for (pos = rcu_dereference((head)->next); pos != (head); \ |
67 | pos = rcu_dereference(pos->next)) | |
68 | ||
7a50dcf7 | 69 | |
63ff4873 | 70 | /* Iterate through elements of the list. |
7a50dcf7 | 71 | */ |
16aa9ee8 DG |
72 | #define cds_list_for_each_entry_rcu(pos, head, member) \ |
73 | for (pos = cds_list_entry(rcu_dereference((head)->next), typeof(*pos), member); \ | |
63ff4873 | 74 | &pos->member != (head); \ |
16aa9ee8 | 75 | pos = cds_list_entry(rcu_dereference(pos->member.next), typeof(*pos), member)) |
7a50dcf7 | 76 | |
63ff4873 | 77 | #endif /* _URCU_RCULIST_H */ |