urcu-pointer: create specific objects and headers to deal with RCU pointers
authorMathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
Thu, 1 Oct 2009 13:48:35 +0000 (09:48 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
Thu, 1 Oct 2009 13:48:35 +0000 (09:48 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
12 files changed:
Makefile.inc
tests/Makefile.inc
urcu-pointer-static.h [new file with mode: 0644]
urcu-pointer.c [new file with mode: 0644]
urcu-pointer.h [new file with mode: 0644]
urcu-qsbr-static.h
urcu-qsbr.c
urcu-qsbr.h
urcu-static.h
urcu.c
urcu.h
urcu/system.h [new file with mode: 0644]

index 3fc3a6c0def2eb8f3236164a1c8528a031dac487..5743c83cddd46ac07dfe151150e2119282c11127 100644 (file)
@@ -26,6 +26,9 @@ urcu.h: urcu/arch.h urcu/arch_uatomic.h
 
 urcu-qsbr.h: urcu/arch.h urcu/arch_uatomic.h
 
+urcu-pointer.o: urcu-pointer.c urcu-pointer.h urcu-pointer-static.h
+       $(CC) -fPIC ${CFLAGS} -c -o $@ $(SRC_DEP)
+
 urcu.o: urcu.c urcu.h
        $(CC) -fPIC ${CFLAGS} -c -o $@ $(SRC_DEP)
 
@@ -38,13 +41,13 @@ urcu-qsbr.o: urcu-qsbr.c urcu-qsbr.h
 urcu-defer.o: urcu-defer.c urcu-defer.h
        $(CC) -fPIC ${CFLAGS} -c -o $@ $(SRC_DEP)
 
-liburcu.so: urcu.o
+liburcu.so: urcu.o urcu-pointer.o
        $(CC) ${LDFLAGS} -fPIC -shared -o $@ $<
 
-liburcu-qsbr.so: urcu-qsbr.o
+liburcu-qsbr.so: urcu-qsbr.o urcu-pointer.o
        $(CC) ${LDFLAGS} -fPIC -shared -o $@ $<
 
-liburcu-mb.so: urcu-mb.o
+liburcu-mb.so: urcu-mb.o urcu-pointer.o
        $(CC) ${LDFLAGS} -fPIC -shared -o $@ $<
 
 liburcu-defer.so: urcu-defer.o
@@ -68,6 +71,7 @@ install: liburcu.so
        cp -f urcu.h urcu-static.h                                      \
                urcu-qsbr.h urcu-qsbr-static.h                          \
                urcu-defer.h urcu-defer-static.h                        \
+               urcu-pointer.h urcu-pointer-static.h                    \
                        /usr/include/
 
 clean:
index 78a609290c60e0966eeb948bd666acbba7fc33b9..92d619e2609bbb82fb3465a384d2aa0b3c824ec5 100644 (file)
@@ -11,11 +11,11 @@ LIBDIR=..
 
 CFLAGS+=-I${LIBDIR}
 
-URCU_SIGNAL=${LIBDIR}/urcu.o ${LIBDIR}/urcu.h
-URCU_SIGNAL_YIELD=${LIBDIR}/urcu-yield.o ${LIBDIR}/urcu.h
-URCU_MB=${LIBDIR}/urcu-mb.o ${LIBDIR}/urcu.h
-URCU_QSBR=${LIBDIR}/urcu-qsbr.o ${LIBDIR}/urcu-qsbr.h
-URCU_MB_DEFER=${LIBDIR}/urcu-mb.o ${LIBDIR}/urcu-defer.o ${LIBDIR}/urcu.h
+URCU_SIGNAL=${LIBDIR}/urcu.o ${LIBDIR}/urcu-pointer.o ${LIBDIR}/urcu.h
+URCU_SIGNAL_YIELD=${LIBDIR}/urcu-yield.o ${LIBDIR}/urcu-pointer.o ${LIBDIR}/urcu.h
+URCU_MB=${LIBDIR}/urcu-mb.o ${LIBDIR}/urcu-pointer.o ${LIBDIR}/urcu.h
+URCU_QSBR=${LIBDIR}/urcu-qsbr.o ${LIBDIR}/urcu-pointer.o ${LIBDIR}/urcu-qsbr.h
+URCU_MB_DEFER=${LIBDIR}/urcu-mb.o ${LIBDIR}/urcu-defer.o ${LIBDIR}/urcu-pointer.o ${LIBDIR}/urcu.h
 
 all: test_urcu test_urcu_dynamic_link test_urcu_timing \
        test_rwlock_timing test_rwlock test_perthreadlock_timing \
diff --git a/urcu-pointer-static.h b/urcu-pointer-static.h
new file mode 100644 (file)
index 0000000..c2ba800
--- /dev/null
@@ -0,0 +1,133 @@
+#ifndef _URCU_POINTER_STATIC_H
+#define _URCU_POINTER_STATIC_H
+
+/*
+ * urcu-pointer-static.h
+ *
+ * Userspace RCU header. Operations on pointers.
+ *
+ * TO BE INCLUDED ONLY IN LGPL-COMPATIBLE CODE. See urcu-pointer.h for
+ * linking dynamically with the userspace rcu library.
+ *
+ * Copyright (c) 2009 Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
+ * Copyright (c) 2009 Paul E. McKenney, IBM Corporation.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * IBM's contributions to this file may be relicensed under LGPLv2 or later.
+ */
+
+#include <urcu/compiler.h>
+#include <urcu/arch.h>
+#include <urcu/system.h>
+#include <urcu/arch_uatomic.h>
+
+/**
+ * _rcu_dereference - reads (copy) a RCU-protected pointer to a local variable
+ * into a RCU read-side critical section. The pointer can later be safely
+ * dereferenced within the critical section.
+ *
+ * This ensures that the pointer copy is invariant thorough the whole critical
+ * section.
+ *
+ * Inserts memory barriers on architectures that require them (currently only
+ * Alpha) and documents which pointers are protected by RCU.
+ *
+ * The compiler memory barrier in LOAD_SHARED() ensures that value-speculative
+ * optimizations (e.g. VSS: Value Speculation Scheduling) does not perform the
+ * data read before the pointer read by speculating the value of the pointer.
+ * Correct ordering is ensured because the pointer is read as a volatile access.
+ * This acts as a global side-effect operation, which forbids reordering of
+ * dependent memory operations. Note that such concern about dependency-breaking
+ * optimizations will eventually be taken care of by the "memory_order_consume"
+ * addition to forthcoming C++ standard.
+ *
+ * Should match rcu_assign_pointer() or rcu_xchg_pointer().
+ */
+
+#define _rcu_dereference(p)     ({                                     \
+                               typeof(p) _________p1 = LOAD_SHARED(p); \
+                               smp_read_barrier_depends();             \
+                               (_________p1);                          \
+                               })
+
+/**
+ * _rcu_cmpxchg_pointer - same as rcu_assign_pointer, but tests if the pointer
+ * is as expected by "old". If succeeds, returns the previous pointer to the
+ * data structure, which can be safely freed after waiting for a quiescent state
+ * using synchronize_rcu(). If fails (unexpected value), returns old (which
+ * should not be freed !).
+ */
+
+#define _rcu_cmpxchg_pointer(p, old, _new)             \
+       ({                                              \
+               if (!__builtin_constant_p(_new) ||      \
+                   ((_new) != NULL))                   \
+                       wmb();                          \
+               uatomic_cmpxchg(p, old, _new);          \
+       })
+
+/**
+ * _rcu_xchg_pointer - same as rcu_assign_pointer, but returns the previous
+ * pointer to the data structure, which can be safely freed after waiting for a
+ * quiescent state using synchronize_rcu().
+ */
+
+#define _rcu_xchg_pointer(p, v)                                \
+       ({                                              \
+               if (!__builtin_constant_p(v) ||         \
+                   ((v) != NULL))                      \
+                       wmb();                          \
+               uatomic_xchg(p, v);                     \
+       })
+
+
+#define _rcu_set_pointer(p, v)                         \
+       ({                                              \
+               if (!__builtin_constant_p(v) ||         \
+                   ((v) != NULL))                      \
+                       wmb();                          \
+               STORE_SHARED(*(p), v);                  \
+       })
+
+/*
+ * _rcu_publish_content - Exchanges the pointer and waits for quiescent state.
+ *
+ * The pointer returned can be freed.
+ */
+#define _rcu_publish_content(p, v)                     \
+       ({                                              \
+               void *oldptr;                           \
+               oldptr = _rcu_xchg_pointer(p, v);       \
+               synchronize_rcu();                      \
+               oldptr;                                 \
+       })
+
+/**
+ * _rcu_assign_pointer - assign (publicize) a pointer to a new data structure
+ * meant to be read by RCU read-side critical sections. Returns the assigned
+ * value.
+ *
+ * Documents which pointers will be dereferenced by RCU read-side critical
+ * sections and adds the required memory barriers on architectures requiring
+ * them. It also makes sure the compiler does not reorder code initializing the
+ * data structure before its publication.
+ *
+ * Should match rcu_dereference_pointer().
+ */
+
+#define _rcu_assign_pointer(p, v)      _rcu_set_pointer(&(p), v)
+
+#endif /* _URCU_POINTER_STATIC_H */
diff --git a/urcu-pointer.c b/urcu-pointer.c
new file mode 100644 (file)
index 0000000..1461c60
--- /dev/null
@@ -0,0 +1,63 @@
+
+/*
+ * urcu-pointer.c
+ *
+ * library wrappers to be used by non-LGPL compatible source code.
+ *
+ * Copyright (c) 2009 Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
+ * Copyright (c) 2009 Paul E. McKenney, IBM Corporation.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * IBM's contributions to this file may be relicensed under LGPLv2 or later.
+ */
+
+#include "urcu-pointer-static.h"
+/* Do not #define _LGPL_SOURCE to ensure we can emit the wrapper symbols */
+#include "urcu-pointer.h"
+
+extern void synchronize_rcu(void);
+
+void *rcu_dereference(void *p)
+{
+       return _rcu_dereference(p);
+}
+
+void *rcu_set_pointer_sym(void **p, void *v)
+{
+       wmb();
+       return STORE_SHARED(*p, v);
+}
+
+void *rcu_xchg_pointer_sym(void **p, void *v)
+{
+       wmb();
+       return uatomic_xchg(p, v);
+}
+
+void *rcu_cmpxchg_pointer_sym(void **p, void *old, void *_new)
+{
+       wmb();
+       return uatomic_cmpxchg(p, old, _new);
+}
+
+void *rcu_publish_content_sym(void **p, void *v)
+{
+       void *oldptr;
+
+       oldptr = _rcu_xchg_pointer(p, v);
+       synchronize_rcu();
+       return oldptr;
+}
diff --git a/urcu-pointer.h b/urcu-pointer.h
new file mode 100644 (file)
index 0000000..748a37a
--- /dev/null
@@ -0,0 +1,106 @@
+#ifndef _URCU_POINTER_H
+#define _URCU_POINTER_H
+
+/*
+ * urcu-pointer.h
+ *
+ * Userspace RCU header. Operations on pointers.
+ *
+ * Copyright (c) 2009 Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
+ * Copyright (c) 2009 Paul E. McKenney, IBM Corporation.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * IBM's contributions to this file may be relicensed under LGPLv2 or later.
+ */
+
+#include <urcu/compiler.h>
+#include <urcu/arch.h>
+#include <urcu/arch_uatomic.h>
+
+#ifdef _LGPL_SOURCE
+
+#include <urcu-pointer-static.h>
+
+/*
+ * rcu_dereference(ptr)
+ *
+ * Fetch a RCU-protected pointer. Typically used to copy the variable ptr to a
+ * local variable.
+ */
+#define rcu_dereference                _rcu_dereference
+
+/*
+ * rcu_cmpxchg_pointer(type **ptr, type *new, type *old)
+ * type *rcu_xchg_pointer(type **ptr, type *new)
+ * type *rcu_set_pointer(type **ptr, type *new)
+ *
+ * RCU pointer updates.
+ * @ptr: address of the pointer to modify
+ * @new: new pointer value
+ * @old: old pointer value (expected)
+ *
+ * return: old pointer value
+ */
+#define rcu_cmpxchg_pointer    _rcu_cmpxchg_pointer
+#define rcu_xchg_pointer       _rcu_xchg_pointer
+#define rcu_set_pointer                _rcu_set_pointer
+
+/*
+ * type *rcu_publish_content(type **ptr, type *new)
+ *
+ * Exchanges the pointer and waits for quiescent state. The pointer returned
+ * can be freed. You are encouraged to use either
+ * - rcu_cmpxchg_pointer
+ * - rcu_xchg_pointer
+ * - rcu_set_pointer
+ * with call_rcu(free, ptr) instead to deal with reclamation more efficiently.
+ */
+#define rcu_publish_content    _rcu_publish_content
+
+#else /* !_LGPL_SOURCE */
+
+extern void *rcu_dereference(void *p);
+
+extern void *rcu_cmpxchg_pointer_sym(void **p, void *old, void *_new);
+#define rcu_cmpxchg_pointer(p, old, _new)              \
+       rcu_cmpxchg_pointer_sym((void **)(p), (old), (_new))
+
+extern void *rcu_xchg_pointer_sym(void **p, void *v);
+#define rcu_xchg_pointer(p, v)                         \
+       rcu_xchg_pointer_sym((void **)(p), (v))
+
+extern void *rcu_set_pointer_sym(void **p, void *v);
+#define rcu_set_pointer(p, v)                          \
+       rcu_set_pointer_sym((void **)(p), (v))
+
+extern void *rcu_publish_content_sym(void **p, void *v);
+#define rcu_publish_content(p, v)                      \
+       rcu_publish_content_sym((void **)(p), (v))
+
+extern void *rcu_assign_pointer_sym(void **p, void *v);
+
+#endif /* !_LGPL_SOURCE */
+
+/*
+ * rcu_assign_pointer(type *ptr, type *new)
+ *
+ * Same as rcu_set_pointer, but takes the pointer to assign to rather than its
+ * address as first parameter. Provided for compatibility with the Linux kernel
+ * RCU semantic.
+ */
+#define rcu_assign_pointer(p, v)       rcu_set_pointer((&p), (v))
+
+#endif /* _URCU_POINTER_H */
index d53a1f4919569e5ada46b6fd3ff83bc8bded341f..d4cb6a98d5acfa5c760e3725b94e7f9437d075c1 100644 (file)
 
 #include <urcu/compiler.h>
 #include <urcu/arch.h>
+#include <urcu/system.h>
 #include <urcu/arch_uatomic.h>
 #include <urcu/list.h>
 
-/*
- * Identify a shared load. A smp_rmc() or smp_mc() should come before the load.
- */
-#define _LOAD_SHARED(p)               ACCESS_ONCE(p)
-
-/*
- * Load a data from shared memory, doing a cache flush if required.
- */
-#define LOAD_SHARED(p)                 \
-       ({                              \
-               smp_rmc();              \
-               _LOAD_SHARED(p);        \
-       })
-
-/*
- * Identify a shared store. A smp_wmc() or smp_mc() should follow the store.
- */
-#define _STORE_SHARED(x, v)    ({ ACCESS_ONCE(x) = (v); })
-
-/*
- * Store v into x, where x is located in shared memory. Performs the required
- * cache flush after writing. Returns v.
- */
-#define STORE_SHARED(x, v)             \
-       ({                              \
-               _STORE_SHARED(x, v);    \
-               smp_wmc();              \
-               (v);                    \
-       })
-
-/**
- * _rcu_dereference - reads (copy) a RCU-protected pointer to a local variable
- * into a RCU read-side critical section. The pointer can later be safely
- * dereferenced within the critical section.
- *
- * This ensures that the pointer copy is invariant thorough the whole critical
- * section.
- *
- * Inserts memory barriers on architectures that require them (currently only
- * Alpha) and documents which pointers are protected by RCU.
- *
- * Should match rcu_assign_pointer() or rcu_xchg_pointer().
- */
-
-#define _rcu_dereference(p)     ({                                     \
-                               typeof(p) _________p1 = LOAD_SHARED(p); \
-                               smp_read_barrier_depends();             \
-                               (_________p1);                          \
-                               })
-
 #define futex(...)             syscall(__NR_futex, __VA_ARGS__)
 #define FUTEX_WAIT             0
 #define FUTEX_WAKE             1
@@ -262,67 +213,4 @@ static inline void _rcu_thread_online(void)
        smp_mb();
 }
 
-/**
- * _rcu_assign_pointer - assign (publicize) a pointer to a new data structure
- * meant to be read by RCU read-side critical sections. Returns the assigned
- * value.
- *
- * Documents which pointers will be dereferenced by RCU read-side critical
- * sections and adds the required memory barriers on architectures requiring
- * them. It also makes sure the compiler does not reorder code initializing the
- * data structure before its publication.
- *
- * Should match rcu_dereference_pointer().
- */
-
-#define _rcu_assign_pointer(p, v)                      \
-       ({                                              \
-               if (!__builtin_constant_p(v) ||         \
-                   ((v) != NULL))                      \
-                       wmb();                          \
-               STORE_SHARED(p, v);                     \
-       })
-
-/**
- * _rcu_cmpxchg_pointer - same as rcu_assign_pointer, but tests if the pointer
- * is as expected by "old". If succeeds, returns the previous pointer to the
- * data structure, which can be safely freed after waiting for a quiescent state
- * using synchronize_rcu(). If fails (unexpected value), returns old (which
- * should not be freed !).
- */
-
-#define _rcu_cmpxchg_pointer(p, old, _new)             \
-       ({                                              \
-               if (!__builtin_constant_p(_new) ||      \
-                   ((_new) != NULL))                   \
-                       wmb();                          \
-               uatomic_cmpxchg(p, old, _new);          \
-       })
-
-/**
- * _rcu_xchg_pointer - same as rcu_assign_pointer, but returns the previous
- * pointer to the data structure, which can be safely freed after waiting for a
- * quiescent state using synchronize_rcu().
- */
-
-#define _rcu_xchg_pointer(p, v)                                \
-       ({                                              \
-               if (!__builtin_constant_p(v) ||         \
-                   ((v) != NULL))                      \
-                       wmb();                          \
-               uatomic_xchg(p, v);                     \
-       })
-
-/*
- * Exchanges the pointer and waits for quiescent state.
- * The pointer returned can be freed.
- */
-#define _rcu_publish_content(p, v)                     \
-       ({                                              \
-               void *oldptr;                           \
-               oldptr = _rcu_xchg_pointer(p, v);       \
-               synchronize_rcu();                      \
-               oldptr;                                 \
-       })
-
 #endif /* _URCU_QSBR_STATIC_H */
index bb98a199d5138664c4f2e03b14ca7a45cde93c98..56d86f9e561d6ea8fc372eed83ffc36f35dc358b 100644 (file)
@@ -278,38 +278,6 @@ void rcu_read_unlock(void)
        _rcu_read_unlock();
 }
 
-void *rcu_dereference(void *p)
-{
-       return _rcu_dereference(p);
-}
-
-void *rcu_assign_pointer_sym(void **p, void *v)
-{
-       wmb();
-       return STORE_SHARED(*p, v);
-}
-
-void *rcu_cmpxchg_pointer_sym(void **p, void *old, void *_new)
-{
-       wmb();
-       return uatomic_cmpxchg(p, old, _new);
-}
-
-void *rcu_xchg_pointer_sym(void **p, void *v)
-{
-       wmb();
-       return uatomic_xchg(p, v);
-}
-
-void *rcu_publish_content_sym(void **p, void *v)
-{
-       void *oldptr;
-
-       oldptr = _rcu_xchg_pointer(p, v);
-       synchronize_rcu();
-       return oldptr;
-}
-
 void rcu_quiescent_state(void)
 {
        _rcu_quiescent_state();
index 6eebdc7a489badf25d6f76e29a964e563142fd83..21c2a2e0c9bf299804c4d6a40aa31a13e41d5186 100644 (file)
 #include <stdlib.h>
 #include <pthread.h>
 
+/*
+ * See urcu-pointer.h and urcu-pointer-static.h for pointer publication headers.
+ */
+#include <urcu-pointer.h>
+
 /*
  * Important !
  *
  * Should only be used in LGPL-compatible code.
  */
 
-#define rcu_dereference                _rcu_dereference
-#define rcu_read_lock          _rcu_read_lock
-#define rcu_read_unlock                _rcu_read_unlock
-
-#define rcu_quiescent_state    _rcu_quiescent_state
-#define rcu_thread_offline     _rcu_thread_offline
-#define rcu_thread_online      _rcu_thread_online
+/*
+ * rcu_read_lock()
+ * rcu_read_unlock()
+ *
+ * Mark the beginning and end of a read-side critical section.
+ * DON'T FORGET TO USE RCU_REGISTER/UNREGISTER_THREAD() FOR EACH THREAD WITH
+ * READ-SIDE CRITICAL SECTION.
+ */
+#define rcu_read_lock()                _rcu_read_lock()
+#define rcu_read_unlock()      _rcu_read_unlock()
 
-#define rcu_assign_pointer     _rcu_assign_pointer
-#define rcu_cmpxchg_pointer    _rcu_cmpxchg_pointer
-#define rcu_xchg_pointer       _rcu_xchg_pointer
-#define rcu_publish_content    _rcu_publish_content
+#define rcu_quiescent_state()  _rcu_quiescent_state()
+#define rcu_thread_offline()   _rcu_thread_offline()
+#define rcu_thread_online()    _rcu_thread_online()
 
 #else /* !_LGPL_SOURCE */
 
@@ -93,29 +100,10 @@ extern void rcu_read_unlock(void);
 
 #endif /* !URCU_DEBUG */
 
-extern void *rcu_dereference(void *p);
-
 extern void rcu_quiescent_state(void);
 extern void rcu_thread_offline(void);
 extern void rcu_thread_online(void);
 
-extern void *rcu_assign_pointer_sym(void **p, void *v);
-
-#define rcu_assign_pointer(p, v)                       \
-       rcu_assign_pointer_sym((void **)(&(p)), (v))
-
-extern void *rcu_cmpxchg_pointer_sym(void **p, void *old, void *_new);
-#define rcu_cmpxchg_pointer(p, old, _new)              \
-       rcu_cmpxchg_pointer_sym((void **)(p), (old), (_new))
-
-extern void *rcu_xchg_pointer_sym(void **p, void *v);
-#define rcu_xchg_pointer(p, v)                         \
-       rcu_xchg_pointer_sym((void **)(p), (v))
-
-extern void *rcu_publish_content_sym(void **p, void *v);
-#define rcu_publish_content(p, v)                      \
-       rcu_publish_content_sym((void **)(p), (v))
-
 #endif /* !_LGPL_SOURCE */
 
 extern void synchronize_rcu(void);
index 7d6d7ac25fbd915e8191f7ece2cad27eddbb9251..30bd7fddbea5372c08aff936751e79225893a314 100644 (file)
 
 #include <urcu/compiler.h>
 #include <urcu/arch.h>
+#include <urcu/system.h>
 #include <urcu/arch_uatomic.h>
 #include <urcu/list.h>
 
-/*
- * Identify a shared load. A smp_rmc() or smp_mc() should come before the load.
- */
-#define _LOAD_SHARED(p)               ACCESS_ONCE(p)
-
-/*
- * Load a data from shared memory, doing a cache flush if required.
- */
-#define LOAD_SHARED(p)                 \
-       ({                              \
-               smp_rmc();              \
-               _LOAD_SHARED(p);        \
-       })
-
-/*
- * Identify a shared store. A smp_wmc() or smp_mc() should follow the store.
- */
-#define _STORE_SHARED(x, v)    ({ ACCESS_ONCE(x) = (v); })
-
-/*
- * Store v into x, where x is located in shared memory. Performs the required
- * cache flush after writing. Returns v.
- */
-#define STORE_SHARED(x, v)             \
-       ({                              \
-               _STORE_SHARED(x, v);    \
-               smp_wmc();              \
-               (v);                    \
-       })
-
-/**
- * _rcu_dereference - reads (copy) a RCU-protected pointer to a local variable
- * into a RCU read-side critical section. The pointer can later be safely
- * dereferenced within the critical section.
- *
- * This ensures that the pointer copy is invariant thorough the whole critical
- * section.
- *
- * Inserts memory barriers on architectures that require them (currently only
- * Alpha) and documents which pointers are protected by RCU.
- *
- * The compiler memory barrier in LOAD_SHARED() ensures that value-speculative
- * optimizations (e.g. VSS: Value Speculation Scheduling) does not perform the
- * data read before the pointer read by speculating the value of the pointer.
- * Correct ordering is ensured because the pointer is read as a volatile access.
- * This acts as a global side-effect operation, which forbids reordering of
- * dependent memory operations. Note that such concern about dependency-breaking
- * optimizations will eventually be taken care of by the "memory_order_consume"
- * addition to forthcoming C++ standard.
- *
- * Should match rcu_assign_pointer() or rcu_xchg_pointer().
- */
-
-#define _rcu_dereference(p)     ({                                     \
-                               typeof(p) _________p1 = LOAD_SHARED(p); \
-                               smp_read_barrier_depends();             \
-                               (_________p1);                          \
-                               })
-
 #define futex(...)             syscall(__NR_futex, __VA_ARGS__)
 #define FUTEX_WAIT             0
 #define FUTEX_WAKE             1
@@ -298,67 +240,4 @@ static inline void _rcu_read_unlock(void)
        }
 }
 
-/**
- * _rcu_assign_pointer - assign (publicize) a pointer to a new data structure
- * meant to be read by RCU read-side critical sections. Returns the assigned
- * value.
- *
- * Documents which pointers will be dereferenced by RCU read-side critical
- * sections and adds the required memory barriers on architectures requiring
- * them. It also makes sure the compiler does not reorder code initializing the
- * data structure before its publication.
- *
- * Should match rcu_dereference_pointer().
- */
-
-#define _rcu_assign_pointer(p, v)                      \
-       ({                                              \
-               if (!__builtin_constant_p(v) ||         \
-                   ((v) != NULL))                      \
-                       wmb();                          \
-               STORE_SHARED(p, v);                     \
-       })
-
-/**
- * _rcu_cmpxchg_pointer - same as rcu_assign_pointer, but tests if the pointer
- * is as expected by "old". If succeeds, returns the previous pointer to the
- * data structure, which can be safely freed after waiting for a quiescent state
- * using synchronize_rcu(). If fails (unexpected value), returns old (which
- * should not be freed !).
- */
-
-#define _rcu_cmpxchg_pointer(p, old, _new)             \
-       ({                                              \
-               if (!__builtin_constant_p(_new) ||      \
-                   ((_new) != NULL))                   \
-                       wmb();                          \
-               uatomic_cmpxchg(p, old, _new);          \
-       })
-
-/**
- * _rcu_xchg_pointer - same as rcu_assign_pointer, but returns the previous
- * pointer to the data structure, which can be safely freed after waiting for a
- * quiescent state using synchronize_rcu().
- */
-
-#define _rcu_xchg_pointer(p, v)                                \
-       ({                                              \
-               if (!__builtin_constant_p(v) ||         \
-                   ((v) != NULL))                      \
-                       wmb();                          \
-               uatomic_xchg(p, v);                     \
-       })
-
-/*
- * Exchanges the pointer and waits for quiescent state.
- * The pointer returned can be freed.
- */
-#define _rcu_publish_content(p, v)                     \
-       ({                                              \
-               void *oldptr;                           \
-               oldptr = _rcu_xchg_pointer(p, v);       \
-               synchronize_rcu();                      \
-               oldptr;                                 \
-       })
-
 #endif /* _URCU_STATIC_H */
diff --git a/urcu.c b/urcu.c
index c13ad634e7cb7b98f24d8c9a5a756eb26487bf7b..8ff39db1331e5a33cfc102b9fb3283e6c58fc2df 100644 (file)
--- a/urcu.c
+++ b/urcu.c
@@ -372,38 +372,6 @@ void rcu_read_unlock(void)
        _rcu_read_unlock();
 }
 
-void *rcu_dereference(void *p)
-{
-       return _rcu_dereference(p);
-}
-
-void *rcu_assign_pointer_sym(void **p, void *v)
-{
-       wmb();
-       return STORE_SHARED(*p, v);
-}
-
-void *rcu_xchg_pointer_sym(void **p, void *v)
-{
-       wmb();
-       return uatomic_xchg(p, v);
-}
-
-void *rcu_cmpxchg_pointer_sym(void **p, void *old, void *_new)
-{
-       wmb();
-       return uatomic_cmpxchg(p, old, _new);
-}
-
-void *rcu_publish_content_sym(void **p, void *v)
-{
-       void *oldptr;
-
-       oldptr = _rcu_xchg_pointer(p, v);
-       synchronize_rcu();
-       return oldptr;
-}
-
 void rcu_register_thread(void)
 {
        urcu_reader.tid = pthread_self();
diff --git a/urcu.h b/urcu.h
index a0aac2195feea64a90043866950cfe0322eb0df7..69c06e409ddaf2bb95d96d27ae6d9369b777d40b 100644 (file)
--- a/urcu.h
+++ b/urcu.h
 #include <stdlib.h>
 #include <pthread.h>
 
+/*
+ * See urcu-pointer.h and urcu-pointer-static.h for pointer publication headers.
+ */
+#include <urcu-pointer.h>
+
 /*
  * Important !
  *
  * Should only be used in LGPL-compatible code.
  */
 
-#define rcu_dereference                _rcu_dereference
-#define rcu_read_lock          _rcu_read_lock
-#define rcu_read_unlock                _rcu_read_unlock
-
-#define rcu_assign_pointer     _rcu_assign_pointer
-#define rcu_cmpxchg_pointer    _rcu_cmpxchg_pointer
-#define rcu_xchg_pointer       _rcu_xchg_pointer
-#define rcu_publish_content    _rcu_publish_content
+/*
+ * rcu_read_lock()
+ * rcu_read_unlock()
+ *
+ * Mark the beginning and end of a read-side critical section.
+ * DON'T FORGET TO USE RCU_REGISTER/UNREGISTER_THREAD() FOR EACH THREAD WITH
+ * READ-SIDE CRITICAL SECTION.
+ */
+#define rcu_read_lock()                _rcu_read_lock()
+#define rcu_read_unlock()      _rcu_read_unlock()
 
 #else /* !_LGPL_SOURCE */
 
 /*
  * library wrappers to be used by non-LGPL compatible source code.
+ * See LGPL-only urcu-pointer-static.h for documentation.
  */
 
 extern void rcu_read_lock(void);
 extern void rcu_read_unlock(void);
 
-extern void *rcu_dereference(void *p);
-
-extern void *rcu_assign_pointer_sym(void **p, void *v);
-
-#define rcu_assign_pointer(p, v)                       \
-       rcu_assign_pointer_sym((void **)(&(p)), (v))
-
-extern void *rcu_cmpxchg_pointer_sym(void **p, void *old, void *_new);
-#define rcu_cmpxchg_pointer(p, old, _new)              \
-       rcu_cmpxchg_pointer_sym((void **)(p), (old), (_new))
-
-extern void *rcu_xchg_pointer_sym(void **p, void *v);
-#define rcu_xchg_pointer(p, v)                         \
-       rcu_xchg_pointer_sym((void **)(p), (v))
-
-extern void *rcu_publish_content_sym(void **p, void *v);
-#define rcu_publish_content(p, v)                      \
-       rcu_publish_content_sym((void **)(p), (v))
-
 #endif /* !_LGPL_SOURCE */
 
 extern void synchronize_rcu(void);
diff --git a/urcu/system.h b/urcu/system.h
new file mode 100644 (file)
index 0000000..e36a13b
--- /dev/null
@@ -0,0 +1,54 @@
+#ifndef _URCU_SYSTEM_H
+#define _URCU_SYSTEM_H
+
+/*
+ * system.h
+ *
+ * System definitions.
+ *
+ * Copyright (c) 2009 Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
+ *
+ * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
+ * OR IMPLIED.  ANY USE IS AT YOUR OWN RISK.
+ *
+ * Permission is hereby granted to use or copy this program
+ * for any purpose,  provided the above notices are retained on all copies.
+ * Permission to modify the code and to distribute modified code is granted,
+ * provided the above notices are retained, and a notice that the code was
+ * modified is included with the above copyright notice.
+ */
+
+#include <urcu/compiler.h>
+#include <urcu/arch.h>
+
+/*
+ * Identify a shared load. A smp_rmc() or smp_mc() should come before the load.
+ */
+#define _LOAD_SHARED(p)               ACCESS_ONCE(p)
+
+/*
+ * Load a data from shared memory, doing a cache flush if required.
+ */
+#define LOAD_SHARED(p)                 \
+       ({                              \
+               smp_rmc();              \
+               _LOAD_SHARED(p);        \
+       })
+
+/*
+ * Identify a shared store. A smp_wmc() or smp_mc() should follow the store.
+ */
+#define _STORE_SHARED(x, v)    ({ ACCESS_ONCE(x) = (v); })
+
+/*
+ * Store v into x, where x is located in shared memory. Performs the required
+ * cache flush after writing. Returns v.
+ */
+#define STORE_SHARED(x, v)             \
+       ({                              \
+               _STORE_SHARED(x, v);    \
+               smp_wmc();              \
+               (v);                    \
+       })
+
+#endif /* _URCU_SYSTEM_H */
This page took 0.0374719999999999 seconds and 4 git commands to generate.