From: Mathieu Desnoyers Date: Tue, 13 Jul 2010 15:57:30 +0000 (-0400) Subject: RCU lock-free stack: don't hold read lock across retry X-Git-Tag: v0.4.7~21 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=2e6c64324e20fc31ccb6af3717e8d6b040869ed6;p=urcu.git RCU lock-free stack: don't hold read lock across retry Be nicer to grace-periods. Signed-off-by: Mathieu Desnoyers --- diff --git a/urcu/rculfstack.h b/urcu/rculfstack.h index 6df6d72..48f6297 100644 --- a/urcu/rculfstack.h +++ b/urcu/rculfstack.h @@ -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 {