X-Git-Url: https://git.liburcu.org/?p=urcu.git;a=blobdiff_plain;f=urcu%2Frculfstack-static.h;h=f541d40508f1ee05d3f046cb0f0d5add5f18c48c;hp=49e5ef4adf905530d82577544d35ae6e1602f895;hb=16aa9ee87cf4364921c36025359be01390338d87;hpb=7520203585dce2fda38454d3630febe0a2b808de diff --git a/urcu/rculfstack-static.h b/urcu/rculfstack-static.h index 49e5ef4..f541d40 100644 --- a/urcu/rculfstack-static.h +++ b/urcu/rculfstack-static.h @@ -33,21 +33,21 @@ extern "C" { #endif -void _rcu_lfs_node_init(struct rcu_lfs_node *node) +void _cds_lfs_node_init_rcu(struct cds_lfs_node_rcu *node) { } -void _rcu_lfs_init(struct rcu_lfs_stack *s) +void _cds_lfs_init_rcu(struct cds_lfs_stack_rcu *s) { s->head = NULL; } -void _rcu_lfs_push(struct rcu_lfs_stack *s, struct rcu_lfs_node *node) +void _cds_lfs_push_rcu(struct cds_lfs_stack_rcu *s, struct cds_lfs_node_rcu *node) { - struct rcu_lfs_node *head = NULL; + struct cds_lfs_node_rcu *head = NULL; for (;;) { - struct rcu_lfs_node *old_head = head; + struct cds_lfs_node_rcu *old_head = head; node->next = head; /* @@ -62,28 +62,34 @@ void _rcu_lfs_push(struct rcu_lfs_stack *s, struct rcu_lfs_node *node) /* * The caller must wait for a grace period to pass before freeing the returned - * node or modifying the rcu_lfs_node structure. + * node or modifying the cds_lfs_node_rcu structure. * Returns NULL if stack is empty. */ -struct rcu_lfs_node * -_rcu_lfs_pop(struct rcu_lfs_stack *s) +struct cds_lfs_node_rcu * +_cds_lfs_pop_rcu(struct cds_lfs_stack_rcu *s) { - struct rcu_lfs_node *head = NULL; - for (;;) { - struct rcu_lfs_node *old_head = head; - struct rcu_lfs_node *next; + struct cds_lfs_node_rcu *head; - if (head) - next = head->next; - else - next = NULL; + rcu_read_lock(); + head = rcu_dereference(s->head); + if (head) { + struct cds_lfs_node_rcu *next = rcu_dereference(head->next); - head = uatomic_cmpxchg(&s->head, old_head, next); - if (old_head == head) - break; + 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; + } } - return head; } #ifdef __cplusplus