RCU lock-free stack: don't hold read lock across retry
authorMathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
Tue, 13 Jul 2010 15:57:30 +0000 (11:57 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
Tue, 13 Jul 2010 15:57:30 +0000 (11:57 -0400)
Be nicer to grace-periods.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
urcu/rculfstack.h

index 6df6d725a584b0719ebfd6a2c70a9d7a98301789..48f6297eb5213dd82234b0a0e8bdd86d548d8a9c 100644 (file)
@@ -43,10 +43,11 @@ void rcu_lfs_init(struct rcu_lfs_stack *s)
 
 void rcu_lfs_push(struct rcu_lfs_stack *s, struct rcu_lfs_node *node)
 {
-       rcu_read_lock();
        for (;;) {
-               struct rcu_lfs_node *head = rcu_dereference(s->head);
+               struct rcu_lfs_node *head;
 
+               rcu_read_lock();
+               head = rcu_dereference(s->head);
                node->next = head;
                /*
                 * uatomic_cmpxchg() implicit memory barrier orders earlier
@@ -57,6 +58,7 @@ void rcu_lfs_push(struct rcu_lfs_stack *s, struct rcu_lfs_node *node)
                        return;
                } else {
                        /* Failure to prepend. Retry. */
+                       rcu_read_unlock();
                        continue;
                }
        }
@@ -70,10 +72,11 @@ void rcu_lfs_push(struct rcu_lfs_stack *s, struct rcu_lfs_node *node)
 struct rcu_lfs_node *
 rcu_lfs_pop(struct rcu_lfs_stack *s)
 {
-       rcu_read_lock();
        for (;;) {
-               struct rcu_lfs_node *head = rcu_dereference(s->head);
+               struct rcu_lfs_node *head;
 
+               rcu_read_lock();
+               head = rcu_dereference(s->head);
                if (head) {
                        struct rcu_lfs_node *next = rcu_dereference(head->next);
 
@@ -82,6 +85,7 @@ rcu_lfs_pop(struct rcu_lfs_stack *s)
                                return head;
                        } else {
                                /* Concurrent modification. Retry. */
+                               rcu_read_unlock();
                                continue;
                        }
                } else {
This page took 0.045634 seconds and 4 git commands to generate.