X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;ds=sidebyside;f=urcu%2Frcuwfqueue.h;fp=urcu%2Frcuwfqueue.h;h=0000000000000000000000000000000000000000;hb=4afee0a75aa60a2640afc9ebccc417c3179b276e;hp=8c1d4a19c2ef573eaaf383952cca30c8b8138a3a;hpb=c97740a3b28836ade49d266e0ef1420f348b0b7d;p=urcu.git diff --git a/urcu/rcuwfqueue.h b/urcu/rcuwfqueue.h deleted file mode 100644 index 8c1d4a1..0000000 --- a/urcu/rcuwfqueue.h +++ /dev/null @@ -1,139 +0,0 @@ -#ifndef _URCU_RCUWFQUEUE_H -#define _URCU_RCUWFQUEUE_H - -/* - * rcuwfqueue.h - * - * Userspace RCU library - RCU Queue with Wait-Free Enqueue/Blocking Dequeue - * - * Copyright 2010 - Mathieu Desnoyers - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#if (!defined(_GNU_SOURCE) && !defined(_LGPL_SOURCE)) -#error "Dynamic loader LGPL wrappers not implemented yet" -#endif - -/* - * RCU queue with wait-free enqueue/blocking dequeue using reference counting. - * Enqueue and dequeue operations hold a RCU read lock to deal with cmpxchg ABA - * problem. This implementation keeps a dummy head node to ensure we can always - * update the queue locklessly. Given that this is a queue, the dummy head node - * must always advance as we dequeue entries. Therefore, we keep a reference - * count on each entry we are dequeueing, so they can be kept as dummy head node - * until the next dequeue, at which point their reference count will be - * decremented. - */ - -#define URCU_WFQ_PERMANENT_REF 128 - -struct rcu_wfq_node { - struct rcu_wfq_node *next; - struct urcu_ref ref; -}; - -struct rcu_wfq_queue { - struct rcu_wfq_node *head, *tail; - struct rcu_wfq_node init; /* Dummy initialization node */ -}; - -void rcu_wfq_node_init(struct rcu_wfq_node *node) -{ - node->next = NULL; - urcu_ref_init(&node->ref); -} - -void rcu_wfq_init(struct rcu_wfq_queue *q) -{ - rcu_wfq_node_init(&q->init); - /* Make sure the initial node is never freed. */ - urcu_ref_set(&q->init.ref, URCU_WFQ_PERMANENT_REF); - /* Set queue end */ - q->head = q->tail = &q->init; -} - -void rcu_wfq_enqueue(struct rcu_wfq_queue *q, struct rcu_wfq_node *node) -{ - struct rcu_wfq_node *old_tail; - - urcu_ref_get(&node->ref); - /* - * uatomic_xchg() implicit memory barrier orders earlier stores to node - * (setting it to NULL and incrementing the refcount) before - * publication. - */ - old_tail = uatomic_xchg(&q->tail, node); - /* - * At this point, dequeuers see a NULL old_tail->next, which indicates - * end of queue. The following store will append "node" to the queue - * from a dequeuer perspective. - */ - STORE_SHARED(old_tail->next, node); -} - -/* - * The entry returned by dequeue must be taken care of by doing a urcu_ref_put, - * which calls the release primitive when the reference count drops to zero. A - * grace period must be waited before performing the actual memory reclamation - * in the release primitive. The wfq node returned by dequeue must not be - * modified/re-used/freed until the reference count reaches zero and a grace - * period has elapsed (after the refcount reached 0). - * - * No need to go on a waitqueue here, as there is no possible state in which the - * list could cause dequeue to busy-loop needlessly while waiting for another - * thread to be scheduled. The queue appears empty until tail->next is set by - * enqueue. - */ -struct rcu_wfq_node * -rcu_wfq_dequeue_blocking(struct rcu_wfq_queue *q, - void (*release)(struct urcu_ref *)) -{ - for (;;) { - struct rcu_wfq_node *head, *next; - - rcu_read_lock(); - head = rcu_dereference(q->head); - next = rcu_dereference(head->next); - if (next) { - if (uatomic_cmpxchg(&q->head, head, next) == head) { - rcu_read_unlock(); - urcu_ref_put(&head->ref, release); - return next; - } else { - /* Concurrently pushed, retry */ - rcu_read_unlock(); - continue; - } - } else { - /* Empty */ - rcu_read_unlock(); - return NULL; - } - } -} - -#ifdef __cplusplus -} -#endif - -#endif /* _URCU_RCUWFQUEUE_H */