X-Git-Url: https://git.liburcu.org/?p=urcu.git;a=blobdiff_plain;f=urcu%2Frculfqueue.h;h=598fa5071a2ca727e43d07a67cb2a62eb4980632;hp=f229cc77ca8d8a741a516dc4f3bbcae2cd67a90e;hb=6a00c945d10d68e174c9fe96b2a98eb124b0d77e;hpb=3d02c34dba0edc4a3554a3862a2ae96d77b3b4e8 diff --git a/urcu/rculfqueue.h b/urcu/rculfqueue.h index f229cc7..598fa50 100644 --- a/urcu/rculfqueue.h +++ b/urcu/rculfqueue.h @@ -23,60 +23,64 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include #include +#include #ifdef __cplusplus extern "C" { #endif -/* - * Lock-free RCU queue 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. - */ +struct cds_lfq_queue_rcu; -struct rcu_lfq_node { - struct rcu_lfq_node *next; - struct urcu_ref ref; +struct cds_lfq_node_rcu { + struct cds_lfq_node_rcu *next; + int dummy; }; -struct rcu_lfq_queue { - struct rcu_lfq_node *head, *tail; - struct rcu_lfq_node init; /* Dummy initialization node */ +struct cds_lfq_queue_rcu { + struct cds_lfq_node_rcu *head, *tail; + void (*queue_call_rcu)(struct rcu_head *head, + void (*func)(struct rcu_head *head)); }; #ifdef _LGPL_SOURCE -#include +#include -#define rcu_lfq_node_init _rcu_lfq_node_init -#define rcu_lfq_init _rcu_lfq_init -#define rcu_lfq_enqueue _rcu_lfq_enqueue -#define rcu_lfq_dequeue _rcu_lfq_dequeue +#define cds_lfq_node_init_rcu _cds_lfq_node_init_rcu +#define cds_lfq_init_rcu _cds_lfq_init_rcu +#define cds_lfq_destroy_rcu _cds_lfq_destroy_rcu +#define cds_lfq_enqueue_rcu _cds_lfq_enqueue_rcu +#define cds_lfq_dequeue_rcu _cds_lfq_dequeue_rcu #else /* !_LGPL_SOURCE */ -extern void rcu_lfq_node_init(struct rcu_lfq_node *node); -extern void rcu_lfq_init(struct rcu_lfq_queue *q); -extern void rcu_lfq_enqueue(struct rcu_lfq_queue *q, struct rcu_lfq_node *node); +extern void cds_lfq_node_init_rcu(struct cds_lfq_node_rcu *node); +extern void cds_lfq_init_rcu(struct cds_lfq_queue_rcu *q, + void queue_call_rcu(struct rcu_head *head, + void (*func)(struct rcu_head *head))); +/* + * The queue should be emptied before calling destroy. + * + * Return 0 on success, -EPERM if queue is not empty. + */ +extern int cds_lfq_destroy_rcu(struct cds_lfq_queue_rcu *q); /* - * 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 after execution of the release callback before - * performing the actual memory reclamation or modifying the rcu_lfq_node - * structure. - * In other words, the entry lfq 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). + * Should be called under rcu read lock critical section. + */ +extern void cds_lfq_enqueue_rcu(struct cds_lfq_queue_rcu *q, + struct cds_lfq_node_rcu *node); + +/* + * Should be called under rcu read lock critical section. + * + * The caller must wait for a grace period to pass before freeing the returned + * node or modifying the cds_lfq_node_rcu structure. + * Returns NULL if queue is empty. */ -extern struct rcu_lfq_node * -rcu_lfq_dequeue(struct rcu_lfq_queue *q, void (*release)(struct urcu_ref *)); +extern +struct cds_lfq_node_rcu *cds_lfq_dequeue_rcu(struct cds_lfq_queue_rcu *q); #endif /* !_LGPL_SOURCE */