Commit | Line | Data |
---|---|---|
4afee0a7 MD |
1 | #ifndef _URCU_WFQUEUE_H |
2 | #define _URCU_WFQUEUE_H | |
3 | ||
4 | /* | |
5 | * wfqueue.h | |
6 | * | |
7 | * Userspace RCU library - Queue with Wait-Free Enqueue/Blocking Dequeue | |
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 <pthread.h> | |
27 | #include <assert.h> | |
28 | #include <urcu/compiler.h> | |
29 | ||
30 | #ifdef __cplusplus | |
31 | extern "C" { | |
32 | #endif | |
33 | ||
4afee0a7 MD |
34 | /* |
35 | * Queue with wait-free enqueue/blocking dequeue. | |
36 | * This implementation adds a dummy head node when the queue is empty to ensure | |
37 | * we can always update the queue locklessly. | |
38 | * | |
39 | * Inspired from half-wait-free/half-blocking queue implementation done by | |
40 | * Paul E. McKenney. | |
41 | */ | |
42 | ||
16aa9ee8 DG |
43 | struct cds_wfq_node { |
44 | struct cds_wfq_node *next; | |
4afee0a7 MD |
45 | }; |
46 | ||
16aa9ee8 DG |
47 | struct cds_wfq_queue { |
48 | struct cds_wfq_node *head, **tail; | |
49 | struct cds_wfq_node dummy; /* Dummy node */ | |
4afee0a7 MD |
50 | pthread_mutex_t lock; |
51 | }; | |
52 | ||
4d001e96 | 53 | #ifdef _LGPL_SOURCE |
4afee0a7 | 54 | |
af7c2dbe | 55 | #include <urcu/static/wfqueue.h> |
4afee0a7 | 56 | |
16aa9ee8 DG |
57 | #define cds_wfq_node_init _cds_wfq_node_init |
58 | #define cds_wfq_init _cds_wfq_init | |
59 | #define cds_wfq_enqueue _cds_wfq_enqueue | |
60 | #define __cds_wfq_dequeue_blocking ___cds_wfq_dequeue_blocking | |
61 | #define cds_wfq_dequeue_blocking _cds_wfq_dequeue_blocking | |
4afee0a7 | 62 | |
4d001e96 | 63 | #else /* !_LGPL_SOURCE */ |
4afee0a7 | 64 | |
16aa9ee8 DG |
65 | extern void cds_wfq_node_init(struct cds_wfq_node *node); |
66 | extern void cds_wfq_init(struct cds_wfq_queue *q); | |
67 | extern void cds_wfq_enqueue(struct cds_wfq_queue *q, struct cds_wfq_node *node); | |
68 | /* __cds_wfq_dequeue_blocking: caller ensures mutual exclusion between dequeues */ | |
69 | extern struct cds_wfq_node *__cds_wfq_dequeue_blocking(struct cds_wfq_queue *q); | |
70 | extern struct cds_wfq_node *cds_wfq_dequeue_blocking(struct cds_wfq_queue *q); | |
4afee0a7 | 71 | |
4d001e96 | 72 | #endif /* !_LGPL_SOURCE */ |
4afee0a7 MD |
73 | |
74 | #ifdef __cplusplus | |
75 | } | |
76 | #endif | |
77 | ||
78 | #endif /* _URCU_WFQUEUE_H */ |