rculfqueue: LGPL-ize
[urcu.git] / urcu / rculfqueue.h
1 #ifndef _URCU_RCULFQUEUE_H
2 #define _URCU_RCULFQUEUE_H
3
4 /*
5 * rculfqueue.h
6 *
7 * Userspace RCU library - Lock-Free RCU Queue
8 *
9 * Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
10 *
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.
15 *
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.
20 *
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
24 */
25
26 #include <urcu/urcu_ref.h>
27 #include <assert.h>
28
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32
33 /*
34 * Lock-free RCU queue using reference counting. Enqueue and dequeue operations
35 * hold a RCU read lock to deal with cmpxchg ABA problem. This implementation
36 * keeps a dummy head node to ensure we can always update the queue locklessly.
37 * Given that this is a queue, the dummy head node must always advance as we
38 * dequeue entries. Therefore, we keep a reference count on each entry we are
39 * dequeueing, so they can be kept as dummy head node until the next dequeue, at
40 * which point their reference count will be decremented.
41 */
42
43 struct rcu_lfq_node {
44 struct rcu_lfq_node *next;
45 struct urcu_ref ref;
46 };
47
48 struct rcu_lfq_queue {
49 struct rcu_lfq_node *head, *tail;
50 struct rcu_lfq_node init; /* Dummy initialization node */
51 };
52
53 #ifdef _LGPL_SOURCE
54
55 #include <urcu/rculfqueue-static.h>
56
57 #define rcu_lfq_node_init _rcu_lfq_node_init
58 #define rcu_lfq_init _rcu_lfq_init
59 #define rcu_lfq_enqueue _rcu_lfq_enqueue
60 #define rcu_lfq_dequeue _rcu_lfq_dequeue
61
62 #else /* !_LGPL_SOURCE */
63
64 extern void rcu_lfq_node_init(struct rcu_lfq_node *node);
65 extern void rcu_lfq_init(struct rcu_lfq_queue *q);
66 extern void rcu_lfq_enqueue(struct rcu_lfq_queue *q, struct rcu_lfq_node *node);
67
68 /*
69 * The entry returned by dequeue must be taken care of by doing a urcu_ref_put,
70 * which calls the release primitive when the reference count drops to zero. A
71 * grace period must be waited after execution of the release callback before
72 * performing the actual memory reclamation or modifying the rcu_lfq_node
73 * structure.
74 * In other words, the entry lfq node returned by dequeue must not be
75 * modified/re-used/freed until the reference count reaches zero and a grace
76 * period has elapsed (after the refcount reached 0).
77 */
78 extern struct rcu_lfq_node *
79 rcu_lfq_dequeue(struct rcu_lfq_queue *q, void (*release)(struct urcu_ref *));
80
81 #endif /* !_LGPL_SOURCE */
82
83 #ifdef __cplusplus
84 }
85 #endif
86
87 #endif /* _URCU_RCULFQUEUE_H */
This page took 0.041374 seconds and 4 git commands to generate.