X-Git-Url: http://git.liburcu.org/?a=blobdiff_plain;f=urcu%2Frculfstack.h;h=a9e624ce792ee2b59ecb648084df5cda73a60e46;hb=ad918eeb98d1ac8b12015050ee60b488e850ac0d;hp=f43c9d8c1e679c344bdb289b445fdd99ed0c466d;hpb=453629a9317adef5b96c3d55e4dcd98db680997a;p=urcu.git diff --git a/urcu/rculfstack.h b/urcu/rculfstack.h index f43c9d8..a9e624c 100644 --- a/urcu/rculfstack.h +++ b/urcu/rculfstack.h @@ -1,3 +1,6 @@ +#ifndef _URCU_RCULFSTACK_H +#define _URCU_RCULFSTACK_H + /* * rculfstack.h * @@ -43,10 +46,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,18 +61,25 @@ void rcu_lfs_push(struct rcu_lfs_stack *s, struct rcu_lfs_node *node) return; } else { /* Failure to prepend. Retry. */ + rcu_read_unlock(); continue; } } } +/* + * The caller must wait for a grace period to pass before freeing the returned + * node. + * Returns NULL if stack is empty. + */ 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); @@ -77,6 +88,7 @@ rcu_lfs_pop(struct rcu_lfs_stack *s) return head; } else { /* Concurrent modification. Retry. */ + rcu_read_unlock(); continue; } } else { @@ -86,3 +98,5 @@ rcu_lfs_pop(struct rcu_lfs_stack *s) } } } + +#endif /* _URCU_RCULFSTACK_H */