X-Git-Url: http://git.liburcu.org/?p=urcu.git;a=blobdiff_plain;f=urcu%2Frculfstack.h;h=20ac26c3d2e8a13b8d64ae5e21a09459da9f53ca;hp=6df6d725a584b0719ebfd6a2c70a9d7a98301789;hb=16aa9ee87cf4364921c36025359be01390338d87;hpb=1c1e940e005b8483982945b4a2a5f40dfeeb2f8c diff --git a/urcu/rculfstack.h b/urcu/rculfstack.h index 6df6d72..20ac26c 100644 --- a/urcu/rculfstack.h +++ b/urcu/rculfstack.h @@ -1,3 +1,6 @@ +#ifndef _URCU_RCULFSTACK_H +#define _URCU_RCULFSTACK_H + /* * rculfstack.h * @@ -20,74 +23,44 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#if (!defined(_GNU_SOURCE) && !defined(_LGPL_SOURCE)) -#error "Dynamic loader LGPL wrappers not implemented yet" +#ifdef __cplusplus +extern "C" { #endif -struct rcu_lfs_node { - struct rcu_lfs_node *next; +struct cds_lfs_node_rcu { + struct cds_lfs_node_rcu *next; }; -struct rcu_lfs_stack { - struct rcu_lfs_node *head; +struct cds_lfs_stack_rcu { + struct cds_lfs_node_rcu *head; }; -void rcu_lfs_node_init(struct rcu_lfs_node *node) -{ -} +#ifdef _LGPL_SOURCE -void rcu_lfs_init(struct rcu_lfs_stack *s) -{ - s->head = NULL; -} +#include -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); +#define cds_lfs_node_init_rcu _cds_lfs_node_init_rcu +#define cds_lfs_init_rcu _cds_lfs_init_rcu +#define cds_lfs_push_rcu _cds_lfs_push_rcu +#define cds_lfs_pop_rcu _cds_lfs_pop_rcu - node->next = head; - /* - * uatomic_cmpxchg() implicit memory barrier orders earlier - * stores to node before publication. - */ - if (uatomic_cmpxchg(&s->head, head, node) == head) { - rcu_read_unlock(); - return; - } else { - /* Failure to prepend. Retry. */ - continue; - } - } -} +#else /* !_LGPL_SOURCE */ + +extern void cds_lfs_node_init_rcu(struct cds_lfs_node_rcu *node); +extern void cds_lfs_init_rcu(struct cds_lfs_stack_rcu *s); +extern void cds_lfs_push_rcu(struct cds_lfs_stack_rcu *s, struct cds_lfs_node_rcu *node); /* * The caller must wait for a grace period to pass before freeing the returned - * node. + * 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) -{ - rcu_read_lock(); - for (;;) { - struct rcu_lfs_node *head = rcu_dereference(s->head); +extern struct cds_lfs_node_rcu *cds_lfs_pop_rcu(struct cds_lfs_stack_rcu *s); - if (head) { - struct rcu_lfs_node *next = rcu_dereference(head->next); +#endif /* !_LGPL_SOURCE */ - if (uatomic_cmpxchg(&s->head, head, next) == head) { - rcu_read_unlock(); - return head; - } else { - /* Concurrent modification. Retry. */ - continue; - } - } else { - /* Empty stack */ - rcu_read_unlock(); - return NULL; - } - } +#ifdef __cplusplus } +#endif + +#endif /* _URCU_RCULFSTACK_H */