X-Git-Url: http://git.liburcu.org/?p=urcu.git;a=blobdiff_plain;f=urcu%2Fstatic%2Frculfstack.h;h=ed6b0d4a6890d7d0f4205106ff5db09627c9f3f1;hp=99d3d4ccc92f8cd22011d099417986e274e08d73;hb=7618919ae496bda84a2efa4f2ad0abe569892a9e;hpb=a2e7bf9ce5de5113c7f59c380b0087e291cd603d diff --git a/urcu/static/rculfstack.h b/urcu/static/rculfstack.h index 99d3d4c..ed6b0d4 100644 --- a/urcu/static/rculfstack.h +++ b/urcu/static/rculfstack.h @@ -27,21 +27,23 @@ */ #include -/* A urcu implementation header should be already included. */ #ifdef __cplusplus extern "C" { #endif +static inline void _cds_lfs_node_init_rcu(struct cds_lfs_node_rcu *node) { } +static inline void _cds_lfs_init_rcu(struct cds_lfs_stack_rcu *s) { s->head = NULL; } +static inline void _cds_lfs_push_rcu(struct cds_lfs_stack_rcu *s, struct cds_lfs_node_rcu *node) { struct cds_lfs_node_rcu *head = NULL; @@ -61,30 +63,35 @@ 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. * Returns NULL if stack is empty. */ +static inline struct cds_lfs_node_rcu * _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; } }