| 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 | |
| 34 | #ifndef CDS_WFQ_DEPRECATED |
| 35 | #define CDS_WFQ_DEPRECATED \ |
| 36 | CDS_DEPRECATED("urcu/wfqueue.h is deprecated. Please use urcu/wfcqueue.h instead.") |
| 37 | #endif |
| 38 | |
| 39 | /* |
| 40 | * Queue with wait-free enqueue/blocking dequeue. |
| 41 | * This implementation adds a dummy head node when the queue is empty to ensure |
| 42 | * we can always update the queue locklessly. |
| 43 | * |
| 44 | * Inspired from half-wait-free/half-blocking queue implementation done by |
| 45 | * Paul E. McKenney. |
| 46 | */ |
| 47 | |
| 48 | struct cds_wfq_node { |
| 49 | struct cds_wfq_node *next; |
| 50 | }; |
| 51 | |
| 52 | struct cds_wfq_queue { |
| 53 | struct cds_wfq_node *head, **tail; |
| 54 | struct cds_wfq_node dummy; /* Dummy node */ |
| 55 | pthread_mutex_t lock; |
| 56 | }; |
| 57 | |
| 58 | #ifdef _LGPL_SOURCE |
| 59 | |
| 60 | #include <urcu/static/wfqueue.h> |
| 61 | |
| 62 | static inline CDS_WFQ_DEPRECATED |
| 63 | void cds_wfq_node_init(struct cds_wfq_node *node) |
| 64 | { |
| 65 | _cds_wfq_node_init(node); |
| 66 | } |
| 67 | |
| 68 | static inline CDS_WFQ_DEPRECATED |
| 69 | void cds_wfq_init(struct cds_wfq_queue *q) |
| 70 | { |
| 71 | _cds_wfq_init(q); |
| 72 | } |
| 73 | |
| 74 | static inline CDS_WFQ_DEPRECATED |
| 75 | void cds_wfq_destroy(struct cds_wfq_queue *q) |
| 76 | { |
| 77 | _cds_wfq_destroy(q); |
| 78 | } |
| 79 | |
| 80 | static inline CDS_WFQ_DEPRECATED |
| 81 | void cds_wfq_enqueue(struct cds_wfq_queue *q, struct cds_wfq_node *node) |
| 82 | { |
| 83 | _cds_wfq_enqueue(q, node); |
| 84 | } |
| 85 | |
| 86 | static inline CDS_WFQ_DEPRECATED |
| 87 | struct cds_wfq_node *__cds_wfq_dequeue_blocking(struct cds_wfq_queue *q) |
| 88 | { |
| 89 | return ___cds_wfq_dequeue_blocking(q); |
| 90 | } |
| 91 | |
| 92 | static inline CDS_WFQ_DEPRECATED |
| 93 | struct cds_wfq_node *cds_wfq_dequeue_blocking(struct cds_wfq_queue *q) |
| 94 | { |
| 95 | return _cds_wfq_dequeue_blocking(q); |
| 96 | } |
| 97 | |
| 98 | #else /* !_LGPL_SOURCE */ |
| 99 | |
| 100 | extern CDS_WFQ_DEPRECATED |
| 101 | void cds_wfq_node_init(struct cds_wfq_node *node); |
| 102 | |
| 103 | extern CDS_WFQ_DEPRECATED |
| 104 | void cds_wfq_init(struct cds_wfq_queue *q); |
| 105 | |
| 106 | extern CDS_WFQ_DEPRECATED |
| 107 | void cds_wfq_destroy(struct cds_wfq_queue *q); |
| 108 | |
| 109 | extern CDS_WFQ_DEPRECATED |
| 110 | void cds_wfq_enqueue(struct cds_wfq_queue *q, struct cds_wfq_node *node); |
| 111 | |
| 112 | /* __cds_wfq_dequeue_blocking: caller ensures mutual exclusion between dequeues */ |
| 113 | extern CDS_WFQ_DEPRECATED |
| 114 | struct cds_wfq_node *__cds_wfq_dequeue_blocking(struct cds_wfq_queue *q); |
| 115 | |
| 116 | extern CDS_WFQ_DEPRECATED |
| 117 | struct cds_wfq_node *cds_wfq_dequeue_blocking(struct cds_wfq_queue *q); |
| 118 | |
| 119 | #endif /* !_LGPL_SOURCE */ |
| 120 | |
| 121 | #ifdef __cplusplus |
| 122 | } |
| 123 | #endif |
| 124 | |
| 125 | #endif /* _URCU_WFQUEUE_H */ |