1 #ifndef _URCU_RCULFSTACK_H
2 #define _URCU_RCULFSTACK_H
7 * Userspace RCU library - Lock-Free RCU Stack
9 * Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
30 #if (!defined(_GNU_SOURCE) && !defined(_LGPL_SOURCE))
31 #error "Dynamic loader LGPL wrappers not implemented yet"
35 struct rcu_lfs_node
*next
;
38 struct rcu_lfs_stack
{
39 struct rcu_lfs_node
*head
;
42 void rcu_lfs_node_init(struct rcu_lfs_node
*node
)
46 void rcu_lfs_init(struct rcu_lfs_stack
*s
)
51 void rcu_lfs_push(struct rcu_lfs_stack
*s
, struct rcu_lfs_node
*node
)
54 struct rcu_lfs_node
*head
;
57 head
= rcu_dereference(s
->head
);
60 * uatomic_cmpxchg() implicit memory barrier orders earlier
61 * stores to node before publication.
63 if (uatomic_cmpxchg(&s
->head
, head
, node
) == head
) {
67 /* Failure to prepend. Retry. */
75 * The caller must wait for a grace period to pass before freeing the returned
76 * node or modifying the rcu_lfs_node structure.
77 * Returns NULL if stack is empty.
80 rcu_lfs_pop(struct rcu_lfs_stack
*s
)
83 struct rcu_lfs_node
*head
;
86 head
= rcu_dereference(s
->head
);
88 struct rcu_lfs_node
*next
= rcu_dereference(head
->next
);
90 if (uatomic_cmpxchg(&s
->head
, head
, next
) == head
) {
94 /* Concurrent modification. Retry. */
110 #endif /* _URCU_RCULFSTACK_H */
This page took 0.030901 seconds and 4 git commands to generate.