CDS API: removal of rcu_read lock/unlock dep, removal of call_rcu argument from init
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 17 Aug 2011 21:54:33 +0000 (17:54 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 17 Aug 2011 21:54:33 +0000 (17:54 -0400)
* API change * for all liburcu-cds* flavors.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
rculfqueue.c
tests/test_urcu_lfq.c
tests/test_urcu_lfs.c
urcu/rculfqueue.h
urcu/rculfstack.h
urcu/static/rculfqueue.h
urcu/static/rculfstack.h

index 09b858791d8a8babc0bff46741e188b423fd23ea..c579e75a759e4e25d0f1780ecabd5c0b1bcd3e2a 100644 (file)
@@ -44,11 +44,9 @@ void cds_lfq_node_init_rcu(struct cds_lfq_node_rcu *node)
        _cds_lfq_node_init_rcu(node);
 }
 
-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)
 {
-       _cds_lfq_init_rcu(q, queue_call_rcu);
+       _cds_lfq_init_rcu(q);
 }
 
 int cds_lfq_destroy_rcu(struct cds_lfq_queue_rcu *q)
index b61a7d4815788af2bcd9e197dc319a8eb053791a..82a90b0cdecc23f05c3572cf6b6819f00ac72531 100644 (file)
@@ -180,9 +180,7 @@ void *thr_enqueuer(void *_count)
                if (!node)
                        goto fail;
                cds_lfq_node_init_rcu(node);
-               rcu_read_lock();
                cds_lfq_enqueue_rcu(&q, node);
-               rcu_read_unlock();
                nr_successful_enqueues++;
 
                if (unlikely(wdelay))
@@ -230,10 +228,7 @@ void *thr_dequeuer(void *_count)
        for (;;) {
                struct cds_lfq_node_rcu *node;
 
-               rcu_read_lock();
                node = cds_lfq_dequeue_rcu(&q);
-               rcu_read_unlock();
-
                if (node) {
                        defer_rcu(free, node);
                        nr_successful_dequeues++;
@@ -262,9 +257,7 @@ void test_end(struct cds_lfq_queue_rcu *q, unsigned long long *nr_dequeues)
        struct cds_lfq_node_rcu *node;
 
        do {
-               rcu_read_lock();
                node = cds_lfq_dequeue_rcu(q);
-               rcu_read_unlock();
                if (node) {
                        free(node);     /* no more concurrent access */
                        (*nr_dequeues)++;
@@ -363,7 +356,7 @@ int main(int argc, char **argv)
        tid_dequeuer = malloc(sizeof(*tid_dequeuer) * nr_dequeuers);
        count_enqueuer = malloc(2 * sizeof(*count_enqueuer) * nr_enqueuers);
        count_dequeuer = malloc(2 * sizeof(*count_dequeuer) * nr_dequeuers);
-       cds_lfq_init_rcu(&q, call_rcu);
+       cds_lfq_init_rcu(&q);
 
        next_aff = 0;
 
index 252454d29aeb46d4758e30b2a7f6b864cc8e3b65..a7f9af3abd5086ee21e73aa0f3269530e612886a 100644 (file)
@@ -229,9 +229,7 @@ void *thr_dequeuer(void *_count)
        for (;;) {
                struct cds_lfs_node_rcu *node;
 
-               rcu_read_lock();
                node = cds_lfs_pop_rcu(&s);
-               rcu_read_unlock();
                if (node) {
                        defer_rcu(free, node);
                        nr_successful_dequeues++;
index e1d64f13d5229e251674919189c8f28d780c8d50..1582694e92abbcfc5bfc8104f2016fb480f41aff 100644 (file)
@@ -39,8 +39,6 @@ struct cds_lfq_node_rcu {
 
 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
@@ -80,9 +78,7 @@ struct cds_lfq_queue_rcu {
 #else /* !_LGPL_SOURCE */
 
 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)));
+extern void cds_lfq_init_rcu(struct cds_lfq_queue_rcu *q);
 /*
  * The queue should be emptied before calling destroy.
  *
@@ -91,13 +87,13 @@ extern void cds_lfq_init_rcu(struct cds_lfq_queue_rcu *q,
 extern 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.
  */
 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.
+ * 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.
index ad83dbe771cd09adf33bf7446c102cecb24666c6..f6739528a650b2bf8c9bb8d41a35dc400a02c16f 100644 (file)
@@ -71,7 +71,7 @@ extern void cds_lfs_init_rcu(struct cds_lfs_stack_rcu *s);
 extern void cds_lfs_push_rcu(struct cds_lfs_stack_rcu *s, struct cds_lfs_node_rcu *node);
 
 /*
- * 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_lfs_node_rcu structure.
index fea6110b4f466cb011d7f3e36f8b923bbd1f75b2..99335c41ec41d33078279e2f843431111cf307e8 100644 (file)
@@ -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;
        }
 }
index ba26231e87206371965c653189596137abb818cd..ed6b0d4a6890d7d0f4205106ff5db09627c9f3f1 100644 (file)
@@ -63,7 +63,7 @@ void _cds_lfs_push_rcu(struct cds_lfs_stack_rcu *s, struct cds_lfs_node_rcu *nod
 }
 
 /*
- * Should be called under rcu read-side lock.
+ * Acts as a RCU reader.
  *
  * The caller must wait for a grace period to pass before freeing the returned
  * node or modifying the cds_lfs_node_rcu structure.
@@ -76,18 +76,22 @@ _cds_lfs_pop_rcu(struct cds_lfs_stack_rcu *s)
        for (;;) {
                struct cds_lfs_node_rcu *head;
 
+               rcu_read_lock();
                head = rcu_dereference(s->head);
                if (head) {
                        struct cds_lfs_node_rcu *next = rcu_dereference(head->next);
 
                        if (uatomic_cmpxchg(&s->head, head, next) == head) {
+                               rcu_read_unlock();
                                return head;
                        } else {
                                /* Concurrent modification. Retry. */
+                               rcu_read_unlock();
                                continue;
                        }
                } else {
                        /* Empty stack */
+                       rcu_read_unlock();
                        return NULL;
                }
        }
This page took 0.031809 seconds and 4 git commands to generate.