X-Git-Url: https://git.liburcu.org/?p=urcu.git;a=blobdiff_plain;f=urcu%2Fstatic%2Frculfqueue.h;h=99335c41ec41d33078279e2f843431111cf307e8;hp=fea6110b4f466cb011d7f3e36f8b923bbd1f75b2;hb=7618919ae496bda84a2efa4f2ad0abe569892a9e;hpb=4a0b347ad068737b5ab0565cd4506f2f3b21e1f2 diff --git a/urcu/static/rculfqueue.h b/urcu/static/rculfqueue.h index fea6110..99335c4 100644 --- a/urcu/static/rculfqueue.h +++ b/urcu/static/rculfqueue.h @@ -88,7 +88,7 @@ void rcu_free_dummy(struct cds_lfq_node_rcu *node) assert(node->dummy); dummy = caa_container_of(node, struct cds_lfq_node_rcu_dummy, parent); - dummy->q->queue_call_rcu(&dummy->head, free_dummy_cb); + call_rcu(&dummy->head, free_dummy_cb); } static inline @@ -109,13 +109,10 @@ void _cds_lfq_node_init_rcu(struct cds_lfq_node_rcu *node) } static inline -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))) +void _cds_lfq_init_rcu(struct cds_lfq_queue_rcu *q) { q->tail = make_dummy(q, NULL); q->head = q->tail; - q->queue_call_rcu = queue_call_rcu; } /* @@ -136,7 +133,7 @@ int _cds_lfq_destroy_rcu(struct cds_lfq_queue_rcu *q) } /* - * Should be called under rcu read lock critical section. + * Acts as a RCU reader. */ static inline void _cds_lfq_enqueue_rcu(struct cds_lfq_queue_rcu *q, @@ -150,6 +147,7 @@ void _cds_lfq_enqueue_rcu(struct cds_lfq_queue_rcu *q, for (;;) { struct cds_lfq_node_rcu *tail, *next; + rcu_read_lock(); tail = rcu_dereference(q->tail); next = uatomic_cmpxchg(&tail->next, NULL, node); if (next == NULL) { @@ -159,6 +157,7 @@ void _cds_lfq_enqueue_rcu(struct cds_lfq_queue_rcu *q, * enqueue might beat us to it, that's fine). */ (void) uatomic_cmpxchg(&q->tail, tail, node); + rcu_read_unlock(); return; } else { /* @@ -166,6 +165,7 @@ void _cds_lfq_enqueue_rcu(struct cds_lfq_queue_rcu *q, * Help moving tail further and retry. */ (void) uatomic_cmpxchg(&q->tail, tail, next); + rcu_read_unlock(); continue; } } @@ -182,7 +182,7 @@ void enqueue_dummy(struct cds_lfq_queue_rcu *q) } /* - * Should be called under rcu read lock critical section. + * Acts as a RCU reader. * * The caller must wait for a grace period to pass before freeing the returned * node or modifying the cds_lfq_node_rcu structure. @@ -194,10 +194,13 @@ struct cds_lfq_node_rcu *_cds_lfq_dequeue_rcu(struct cds_lfq_queue_rcu *q) for (;;) { struct cds_lfq_node_rcu *head, *next; + rcu_read_lock(); head = rcu_dereference(q->head); next = rcu_dereference(head->next); - if (head->dummy && next == NULL) + if (head->dummy && next == NULL) { + rcu_read_unlock(); return NULL; /* empty */ + } /* * We never, ever allow dequeue to get to a state where * the queue is empty (we need at least one node in the @@ -209,13 +212,17 @@ struct cds_lfq_node_rcu *_cds_lfq_dequeue_rcu(struct cds_lfq_queue_rcu *q) enqueue_dummy(q); next = rcu_dereference(head->next); } - if (uatomic_cmpxchg(&q->head, head, next) != head) + if (uatomic_cmpxchg(&q->head, head, next) != head) { + rcu_read_unlock(); continue; /* Concurrently pushed. */ + } if (head->dummy) { /* Free dummy after grace period. */ rcu_free_dummy(head); + rcu_read_unlock(); continue; /* try again */ } + rcu_read_unlock(); return head; } }