Commit | Line | Data |
---|---|---|
d3d3857f MJ |
1 | // SPDX-FileCopyrightText: 2010 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
2 | // | |
3 | // SPDX-License-Identifier: LGPL-2.1-or-later | |
4 | ||
4afee0a7 MD |
5 | #ifndef _URCU_WFQUEUE_H |
6 | #define _URCU_WFQUEUE_H | |
7 | ||
8 | /* | |
4afee0a7 | 9 | * Userspace RCU library - Queue with Wait-Free Enqueue/Blocking Dequeue |
4afee0a7 MD |
10 | */ |
11 | ||
12 | #include <pthread.h> | |
4afee0a7 MD |
13 | #include <urcu/compiler.h> |
14 | ||
15 | #ifdef __cplusplus | |
16 | extern "C" { | |
17 | #endif | |
18 | ||
14748510 MD |
19 | #ifndef CDS_WFQ_DEPRECATED |
20 | #define CDS_WFQ_DEPRECATED \ | |
706d1165 | 21 | CDS_DEPRECATED("urcu/wfqueue.h is deprecated. Please use urcu/wfcqueue.h instead.") |
14748510 MD |
22 | #endif |
23 | ||
4afee0a7 MD |
24 | /* |
25 | * Queue with wait-free enqueue/blocking dequeue. | |
26 | * This implementation adds a dummy head node when the queue is empty to ensure | |
27 | * we can always update the queue locklessly. | |
28 | * | |
29 | * Inspired from half-wait-free/half-blocking queue implementation done by | |
30 | * Paul E. McKenney. | |
31 | */ | |
32 | ||
16aa9ee8 DG |
33 | struct cds_wfq_node { |
34 | struct cds_wfq_node *next; | |
4afee0a7 MD |
35 | }; |
36 | ||
16aa9ee8 DG |
37 | struct cds_wfq_queue { |
38 | struct cds_wfq_node *head, **tail; | |
39 | struct cds_wfq_node dummy; /* Dummy node */ | |
4afee0a7 MD |
40 | pthread_mutex_t lock; |
41 | }; | |
42 | ||
4d001e96 | 43 | #ifdef _LGPL_SOURCE |
4afee0a7 | 44 | |
af7c2dbe | 45 | #include <urcu/static/wfqueue.h> |
4afee0a7 | 46 | |
14748510 MD |
47 | static inline CDS_WFQ_DEPRECATED |
48 | void cds_wfq_node_init(struct cds_wfq_node *node) | |
49 | { | |
50 | _cds_wfq_node_init(node); | |
51 | } | |
52 | ||
53 | static inline CDS_WFQ_DEPRECATED | |
54 | void cds_wfq_init(struct cds_wfq_queue *q) | |
55 | { | |
56 | _cds_wfq_init(q); | |
57 | } | |
58 | ||
200d100e MD |
59 | static inline CDS_WFQ_DEPRECATED |
60 | void cds_wfq_destroy(struct cds_wfq_queue *q) | |
61 | { | |
62 | _cds_wfq_destroy(q); | |
63 | } | |
64 | ||
14748510 MD |
65 | static inline CDS_WFQ_DEPRECATED |
66 | void cds_wfq_enqueue(struct cds_wfq_queue *q, struct cds_wfq_node *node) | |
67 | { | |
68 | _cds_wfq_enqueue(q, node); | |
69 | } | |
70 | ||
71 | static inline CDS_WFQ_DEPRECATED | |
72 | struct cds_wfq_node *__cds_wfq_dequeue_blocking(struct cds_wfq_queue *q) | |
73 | { | |
74 | return ___cds_wfq_dequeue_blocking(q); | |
75 | } | |
76 | ||
77 | static inline CDS_WFQ_DEPRECATED | |
78 | struct cds_wfq_node *cds_wfq_dequeue_blocking(struct cds_wfq_queue *q) | |
79 | { | |
80 | return _cds_wfq_dequeue_blocking(q); | |
81 | } | |
4afee0a7 | 82 | |
4d001e96 | 83 | #else /* !_LGPL_SOURCE */ |
4afee0a7 | 84 | |
14748510 MD |
85 | extern CDS_WFQ_DEPRECATED |
86 | void cds_wfq_node_init(struct cds_wfq_node *node); | |
87 | ||
88 | extern CDS_WFQ_DEPRECATED | |
89 | void cds_wfq_init(struct cds_wfq_queue *q); | |
90 | ||
200d100e MD |
91 | extern CDS_WFQ_DEPRECATED |
92 | void cds_wfq_destroy(struct cds_wfq_queue *q); | |
93 | ||
14748510 MD |
94 | extern CDS_WFQ_DEPRECATED |
95 | void cds_wfq_enqueue(struct cds_wfq_queue *q, struct cds_wfq_node *node); | |
96 | ||
16aa9ee8 | 97 | /* __cds_wfq_dequeue_blocking: caller ensures mutual exclusion between dequeues */ |
14748510 MD |
98 | extern CDS_WFQ_DEPRECATED |
99 | struct cds_wfq_node *__cds_wfq_dequeue_blocking(struct cds_wfq_queue *q); | |
100 | ||
101 | extern CDS_WFQ_DEPRECATED | |
102 | struct cds_wfq_node *cds_wfq_dequeue_blocking(struct cds_wfq_queue *q); | |
4afee0a7 | 103 | |
4d001e96 | 104 | #endif /* !_LGPL_SOURCE */ |
4afee0a7 MD |
105 | |
106 | #ifdef __cplusplus | |
107 | } | |
108 | #endif | |
109 | ||
110 | #endif /* _URCU_WFQUEUE_H */ |