rculfstack: LGPL-ize
[urcu.git] / urcu / rculfstack.h
index 6df6d725a584b0719ebfd6a2c70a9d7a98301789..a33fcb1a7eaa29a7d80b798906c84b6303048623 100644 (file)
@@ -1,3 +1,6 @@
+#ifndef _URCU_RCULFSTACK_H
+#define _URCU_RCULFSTACK_H
+
 /*
  * rculfstack.h
  *
@@ -20,8 +23,8 @@
  * 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 {
@@ -32,62 +35,32 @@ struct rcu_lfs_stack {
        struct rcu_lfs_node *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 <urcu/rculfstack-static.h>
 
-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 rcu_lfs_node_init      _rcu_lfs_node_init
+#define rcu_lfs_init           _rcu_lfs_init
+#define rcu_lfs_push           _rcu_lfs_push
+#define rcu_lfs_pop            _rcu_lfs_pop
 
-               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 rcu_lfs_node_init(struct rcu_lfs_node *node);
+extern void rcu_lfs_init(struct rcu_lfs_stack *s);
+extern 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.
+ * node or modifying the rcu_lfs_node 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 rcu_lfs_node *rcu_lfs_pop(struct rcu_lfs_stack *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 */
This page took 0.025186 seconds and 4 git commands to generate.