From ec4e58a3aba2084440012f8ccac3a31eb6101183 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Mon, 28 Sep 2009 15:54:13 -0400 Subject: [PATCH] Cleanup headers * atomic_ -> uatomic (to remove namespace clash with libkcompat) * moved arch.h, compiler.h, arch_uatomic.h to /usr/include/urcu/ to make sure we do not pollute system headers. Also add call_rcu() documentation to README. Signed-off-by: Mathieu Desnoyers --- Makefile.inc | 20 +++--- README | 9 +++ tests/Makefile.inc | 9 +-- tests/api_gcc.h | 1 - tests/rcutorture.h | 8 +-- tests/test_looplen.c | 4 +- tests/test_mutex.c | 4 +- tests/test_perthreadlock.c | 4 +- tests/test_perthreadlock_timing.c | 4 +- tests/test_qsbr.c | 4 +- tests/test_qsbr_gc.c | 4 +- tests/test_qsbr_timing.c | 4 +- tests/test_rwlock.c | 4 +- tests/test_rwlock_timing.c | 4 +- tests/{test_atomic.c => test_uatomic.c} | 40 +++++------ tests/test_urcu.c | 4 +- tests/test_urcu_defer.c | 6 +- tests/test_urcu_gc.c | 4 +- tests/test_urcu_timing.c | 4 +- tests/urcu-asm.c | 2 +- tests/urcutorture.c | 4 +- urcu-defer-static.h | 4 +- urcu-defer.c | 10 +-- urcu-qsbr-static.h | 12 ++-- urcu-qsbr.c | 10 +-- urcu-static.h | 12 ++-- urcu.c | 10 +-- arch_ppc.h => urcu/arch_ppc.h | 10 +-- arch_s390.h => urcu/arch_s390.h | 2 +- arch_atomic_ppc.h => urcu/arch_uatomic_ppc.h | 48 +++++++------- .../arch_uatomic_s390.h | 24 +++---- arch_atomic_x86.h => urcu/arch_uatomic_x86.h | 66 +++++++++---------- arch_x86.h => urcu/arch_x86.h | 10 +-- compiler.h => urcu/compiler.h | 6 +- 34 files changed, 187 insertions(+), 184 deletions(-) rename tests/{test_atomic.c => test_uatomic.c} (52%) rename arch_ppc.h => urcu/arch_ppc.h (95%) rename arch_s390.h => urcu/arch_s390.h (98%) rename arch_atomic_ppc.h => urcu/arch_uatomic_ppc.h (78%) rename arch_atomic_s390.h => urcu/arch_uatomic_s390.h (80%) rename arch_atomic_x86.h => urcu/arch_uatomic_x86.h (81%) rename arch_x86.h => urcu/arch_x86.h (96%) rename compiler.h => urcu/compiler.h (95%) diff --git a/Makefile.inc b/Makefile.inc index ae62f54..cde31cc 100644 --- a/Makefile.inc +++ b/Makefile.inc @@ -16,15 +16,15 @@ ifeq (${ARCHTYPE},) @exit 1 endif -arch.h: arch_${ARCHTYPE}.h - cp -f arch_${ARCHTYPE}.h arch.h +urcu/arch.h: urcu/arch_${ARCHTYPE}.h + cp -f urcu/arch_${ARCHTYPE}.h urcu/arch.h -arch_atomic.h: arch_atomic_${ARCHTYPE}.h - cp -f arch_atomic_${ARCHTYPE}.h arch_atomic.h +urcu/arch_uatomic.h: urcu/arch_uatomic_${ARCHTYPE}.h + cp -f urcu/arch_uatomic_${ARCHTYPE}.h urcu/arch_uatomic.h -urcu.h: arch.h arch_atomic.h +urcu.h: urcu/arch.h urcu/arch_uatomic.h -urcu-qsbr.h: arch.h arch_atomic.h +urcu-qsbr.h: urcu/arch.h urcu/arch_uatomic.h urcu.o: urcu.c urcu.h $(CC) -fPIC ${CFLAGS} -c -o $@ $(SRC_DEP) @@ -61,12 +61,14 @@ subdirs: install: liburcu.so cp -f liburcu.so liburcu-mb.so liburcu-qsbr.so liburcu-defer.so \ /usr/lib/ - cp -f arch.h arch_atomic.h compiler.h \ - urcu.h urcu-static.h \ + mkdir -p /usr/include/urcu + cp -f urcu/arch.h urcu/arch_uatomic.h urcu/compiler.h \ + /usr/include/urcu/ + cp -f urcu.h urcu-static.h \ urcu-qsbr.h urcu-qsbr-static.h \ urcu-defer.h urcu-defer-static.h \ /usr/include/ clean: - rm -f *.o *.so arch.h arch_atomic.h + rm -f *.o *.so urcu/arch.h urcu/arch_uatomic.h -for d in ${DIRS}; do cd $${d}; ${MAKE} clean; done diff --git a/README b/README index b47fe48..e5c04b1 100644 --- a/README +++ b/README @@ -70,6 +70,15 @@ Writing After, synchronize_rcu() must be called. When it returns, the old values are not in usage anymore. +Usage of liburcu-defer + + * #include + * Link with "-lurcu-defer" + * Provides call_rcu() primitive to enqueue delayed callbacks. Queued + callbacks are executed in batch periodically after a grace period. + Do _not_ use call_rcu() within a read-side critical section, because + it may call synchronize_rcu() if the thread queue is full. + Being careful with signals The liburcu library uses signals internally. The signal handler is diff --git a/tests/Makefile.inc b/tests/Makefile.inc index f62256b..20eef58 100644 --- a/tests/Makefile.inc +++ b/tests/Makefile.inc @@ -9,7 +9,7 @@ endif LIBDIR=.. -CFLAGS+=-I ${LIBDIR} +CFLAGS+=-I${LIBDIR} URCU_SIGNAL=${LIBDIR}/urcu.o ${LIBDIR}/urcu.h URCU_SIGNAL_YIELD=${LIBDIR}/urcu-yield.o ${LIBDIR}/urcu.h @@ -24,7 +24,7 @@ all: test_urcu test_urcu_dynamic_link test_urcu_timing \ urcutorture-yield test_mutex test_looplen test_urcu_gc \ test_urcu_gc_mb test_qsbr_gc test_qsbr_lgc test_urcu_lgc \ test_urcu_lgc_mb test_qsbr_dynamic_link test_urcu_mb_defer \ - test_atomic + test_uatomic api.h: ${APIHEADER} cp -f ${APIHEADER} api.h @@ -109,7 +109,7 @@ urcutorture: urcutorture.c rcutorture.h api.h ${URCU_SIGNAL} urcutorture-yield: urcutorture.c ${URCU_SIGNAL_YIELD} rcutorture.h api.h $(CC) -DDEBUG_YIELD ${CFLAGS} $(LDFLAGS) -o $@ $(SRC_DEP) -test_atomic: test_atomic.c ../arch_atomic.h +test_uatomic: test_uatomic.c ../urcu/arch_uatomic.h $(CC) ${CFLAGS} $(LDFLAGS) -o $@ $(SRC_DEP) ,PHONY: clean @@ -122,4 +122,5 @@ clean: urcutorture-yield liburcu.so api.h \ test_mutex test_urcu_gc test_urcu_gc_mb urcu-asm-1.S \ test_qsbr_lgc test_qsbr_gc test_looplen test_urcu_lgc \ - test_urcu_lgc_mb test_qsbr_dynamic_link test_urcu_mb_defer + test_urcu_lgc_mb test_qsbr_dynamic_link test_urcu_mb_defer \ + test_uatomic diff --git a/tests/api_gcc.h b/tests/api_gcc.h index 721af0a..c53b2c1 100644 --- a/tests/api_gcc.h +++ b/tests/api_gcc.h @@ -285,7 +285,6 @@ cmpxchg(volatile long *ptr, long oldval, long newval) #include #include #include -#include /* #include "atomic.h" */ /* diff --git a/tests/rcutorture.h b/tests/rcutorture.h index 7d4948e..712d59d 100644 --- a/tests/rcutorture.h +++ b/tests/rcutorture.h @@ -116,7 +116,7 @@ void *rcu_read_perf_test(void *arg) rcu_register_thread(); run_on(me); - atomic_inc(&nthreadsrunning); + uatomic_inc(&nthreadsrunning); while (goflag == GOFLAG_INIT) poll(NULL, 0, 1); mark_rcu_quiescent_state(); @@ -141,7 +141,7 @@ void *rcu_update_perf_test(void *arg) { long long n_updates_local = 0; - atomic_inc(&nthreadsrunning); + uatomic_inc(&nthreadsrunning); while (goflag == GOFLAG_INIT) poll(NULL, 0, 1); while (goflag == GOFLAG_RUN) { @@ -156,7 +156,7 @@ void perftestinit(void) { init_per_thread(n_reads_pt, 0LL); init_per_thread(n_updates_pt, 0LL); - atomic_set(&nthreadsrunning, 0); + uatomic_set(&nthreadsrunning, 0); } void perftestrun(int nthreads, int nreaders, int nupdaters) @@ -165,7 +165,7 @@ void perftestrun(int nthreads, int nreaders, int nupdaters) int duration = 1; smp_mb(); - while (atomic_read(&nthreadsrunning) < nthreads) + while (uatomic_read(&nthreadsrunning) < nthreads) poll(NULL, 0, 1); goflag = GOFLAG_RUN; smp_mb(); diff --git a/tests/test_looplen.c b/tests/test_looplen.c index 5006951..9e2ee2b 100644 --- a/tests/test_looplen.c +++ b/tests/test_looplen.c @@ -33,7 +33,7 @@ #include #include -#include "../arch.h" +#include #if defined(_syscall0) _syscall0(pid_t, gettid) @@ -55,7 +55,7 @@ static inline pid_t gettid(void) #else #define debug_yield_read() #endif -#include "../urcu.h" +#include static inline void loop_sleep(unsigned long l) { diff --git a/tests/test_mutex.c b/tests/test_mutex.c index e94819a..e3b1b64 100644 --- a/tests/test_mutex.c +++ b/tests/test_mutex.c @@ -33,7 +33,7 @@ #include #include -#include "../arch.h" +#include /* Make this big enough to include the POWER5+ L3 cacheline size of 256B */ #define CACHE_LINE_SIZE 4096 @@ -61,7 +61,7 @@ static inline pid_t gettid(void) #else #define debug_yield_read() #endif -#include "../urcu.h" +#include struct test_array { int a; diff --git a/tests/test_perthreadlock.c b/tests/test_perthreadlock.c index 7402f01..ea47e46 100644 --- a/tests/test_perthreadlock.c +++ b/tests/test_perthreadlock.c @@ -33,7 +33,7 @@ #include #include -#include "../arch.h" +#include /* Make this big enough to include the POWER5+ L3 cacheline size of 256B */ #define CACHE_LINE_SIZE 4096 @@ -61,7 +61,7 @@ static inline pid_t gettid(void) #else #define debug_yield_read() #endif -#include "../urcu.h" +#include struct test_array { int a; diff --git a/tests/test_perthreadlock_timing.c b/tests/test_perthreadlock_timing.c index d5bd912..10720cb 100644 --- a/tests/test_perthreadlock_timing.c +++ b/tests/test_perthreadlock_timing.c @@ -32,7 +32,7 @@ #include #include -#include "../arch.h" +#include /* Make this big enough to include the POWER5+ L3 cacheline size of 256B */ #define CACHE_LINE_SIZE 4096 @@ -52,7 +52,7 @@ static inline pid_t gettid(void) } #endif -#include "../urcu.h" +#include struct test_array { int a; diff --git a/tests/test_qsbr.c b/tests/test_qsbr.c index 4379771..cf2fec2 100644 --- a/tests/test_qsbr.c +++ b/tests/test_qsbr.c @@ -33,7 +33,7 @@ #include #include -#include "../arch.h" +#include /* Make this big enough to include the POWER5+ L3 cacheline size of 256B */ #define CACHE_LINE_SIZE 4096 @@ -61,7 +61,7 @@ static inline pid_t gettid(void) #else #define debug_yield_read() #endif -#include "../urcu-qsbr.h" +#include "urcu-qsbr.h" struct test_array { int a; diff --git a/tests/test_qsbr_gc.c b/tests/test_qsbr_gc.c index 004672d..d32d1a0 100644 --- a/tests/test_qsbr_gc.c +++ b/tests/test_qsbr_gc.c @@ -33,7 +33,7 @@ #include #include -#include "../arch.h" +#include /* Make this big enough to include the POWER5+ L3 cacheline size of 256B */ #define CACHE_LINE_SIZE 4096 @@ -57,7 +57,7 @@ static inline pid_t gettid(void) #endif #define _LGPL_SOURCE -#include "../urcu-qsbr.h" +#include struct test_array { int a; diff --git a/tests/test_qsbr_timing.c b/tests/test_qsbr_timing.c index 2a8963a..3585f83 100644 --- a/tests/test_qsbr_timing.c +++ b/tests/test_qsbr_timing.c @@ -30,7 +30,7 @@ #include #include #include -#include "../arch.h" +#include /* Make this big enough to include the POWER5+ L3 cacheline size of 256B */ #define CACHE_LINE_SIZE 4096 @@ -51,7 +51,7 @@ static inline pid_t gettid(void) #endif #define _LGPL_SOURCE -#include "../urcu-qsbr.h" +#include pthread_mutex_t rcu_copy_mutex = PTHREAD_MUTEX_INITIALIZER; diff --git a/tests/test_rwlock.c b/tests/test_rwlock.c index c7edd32..d3f072c 100644 --- a/tests/test_rwlock.c +++ b/tests/test_rwlock.c @@ -33,7 +33,7 @@ #include #include -#include "../arch.h" +#include /* Make this big enough to include the POWER5+ L3 cacheline size of 256B */ #define CACHE_LINE_SIZE 4096 @@ -61,7 +61,7 @@ static inline pid_t gettid(void) #else #define debug_yield_read() #endif -#include "../urcu.h" +#include struct test_array { int a; diff --git a/tests/test_rwlock_timing.c b/tests/test_rwlock_timing.c index 5bc93d3..b26f83d 100644 --- a/tests/test_rwlock_timing.c +++ b/tests/test_rwlock_timing.c @@ -31,7 +31,7 @@ #include #include #include -#include "../arch.h" +#include /* Make this big enough to include the POWER5+ L3 cacheline size of 256B */ #define CACHE_LINE_SIZE 4096 @@ -51,7 +51,7 @@ static inline pid_t gettid(void) } #endif -#include "../urcu.h" +#include struct test_array { int a; diff --git a/tests/test_atomic.c b/tests/test_uatomic.c similarity index 52% rename from tests/test_atomic.c rename to tests/test_uatomic.c index 585c8ca..6c11a2d 100644 --- a/tests/test_atomic.c +++ b/tests/test_uatomic.c @@ -1,6 +1,6 @@ #include -#include #include +#include #if (defined(__i386__) || defined(__x86_64__)) #define HAS_ATOMIC_BYTE @@ -24,30 +24,30 @@ static struct testvals vals; do { \ __typeof__(*(ptr)) v; \ \ - atomic_add(ptr, 10); \ - assert(atomic_read(ptr) == 10); \ - atomic_add(ptr, -11UL); \ - assert(atomic_read(ptr) == (__typeof__(*(ptr)))-1UL); \ - v = cmpxchg(ptr, -1UL, 22); \ - assert(atomic_read(ptr) == 22); \ + uatomic_add(ptr, 10); \ + assert(uatomic_read(ptr) == 10); \ + uatomic_add(ptr, -11UL); \ + assert(uatomic_read(ptr) == (__typeof__(*(ptr)))-1UL); \ + v = uatomic_cmpxchg(ptr, -1UL, 22); \ + assert(uatomic_read(ptr) == 22); \ assert(v == (__typeof__(*(ptr)))-1UL); \ - v = cmpxchg(ptr, 33, 44); \ - assert(atomic_read(ptr) == 22); \ + v = uatomic_cmpxchg(ptr, 33, 44); \ + assert(uatomic_read(ptr) == 22); \ assert(v == 22); \ - v = xchg(ptr, 55); \ - assert(atomic_read(ptr) == 55); \ + v = uatomic_xchg(ptr, 55); \ + assert(uatomic_read(ptr) == 55); \ assert(v == 22); \ - atomic_set(ptr, 22); \ - atomic_inc(ptr); \ - assert(atomic_read(ptr) == 23); \ - atomic_dec(ptr); \ - assert(atomic_read(ptr) == 22); \ - v = atomic_add_return(ptr, 100); \ + uatomic_set(ptr, 22); \ + uatomic_inc(ptr); \ + assert(uatomic_read(ptr) == 23); \ + uatomic_dec(ptr); \ + assert(uatomic_read(ptr) == 22); \ + v = uatomic_add_return(ptr, 100); \ assert(v == 122); \ - assert(atomic_read(ptr) == 122); \ - v = atomic_sub_return(ptr, 1); \ + assert(uatomic_read(ptr) == 122); \ + v = uatomic_sub_return(ptr, 1); \ assert(v == 121); \ - assert(atomic_read(ptr) == 121); \ + assert(uatomic_read(ptr) == 121); \ } while (0) int main(int argc, char **argv) diff --git a/tests/test_urcu.c b/tests/test_urcu.c index 18683bf..8d090eb 100644 --- a/tests/test_urcu.c +++ b/tests/test_urcu.c @@ -33,7 +33,7 @@ #include #include -#include "../arch.h" +#include /* Make this big enough to include the POWER5+ L3 cacheline size of 256B */ #define CACHE_LINE_SIZE 4096 @@ -61,7 +61,7 @@ static inline pid_t gettid(void) #else #define debug_yield_read() #endif -#include "../urcu.h" +#include struct test_array { int a; diff --git a/tests/test_urcu_defer.c b/tests/test_urcu_defer.c index 0961b8d..1c6f742 100644 --- a/tests/test_urcu_defer.c +++ b/tests/test_urcu_defer.c @@ -33,7 +33,7 @@ #include #include -#include "../arch.h" +#include /* Make this big enough to include the POWER5+ L3 cacheline size of 256B */ #define CACHE_LINE_SIZE 4096 @@ -61,8 +61,8 @@ static inline pid_t gettid(void) #else #define debug_yield_read() #endif -#include "../urcu.h" -#include "../urcu-defer.h" +#include +#include struct test_array { int a; diff --git a/tests/test_urcu_gc.c b/tests/test_urcu_gc.c index 213c68b..60f7816 100644 --- a/tests/test_urcu_gc.c +++ b/tests/test_urcu_gc.c @@ -33,7 +33,7 @@ #include #include -#include "../arch.h" +#include /* Make this big enough to include the POWER5+ L3 cacheline size of 256B */ #define CACHE_LINE_SIZE 4096 @@ -61,7 +61,7 @@ static inline pid_t gettid(void) #else #define debug_yield_read() #endif -#include "../urcu.h" +#include struct test_array { int a; diff --git a/tests/test_urcu_timing.c b/tests/test_urcu_timing.c index a3ca783..27d9730 100644 --- a/tests/test_urcu_timing.c +++ b/tests/test_urcu_timing.c @@ -30,7 +30,7 @@ #include #include #include -#include "../arch.h" +#include /* Make this big enough to include the POWER5+ L3 cacheline size of 256B */ #define CACHE_LINE_SIZE 4096 @@ -51,7 +51,7 @@ static inline pid_t gettid(void) #endif #define _LGPL_SOURCE -#include "../urcu.h" +#include pthread_mutex_t rcu_copy_mutex = PTHREAD_MUTEX_INITIALIZER; diff --git a/tests/urcu-asm.c b/tests/urcu-asm.c index 66be709..dd26604 100644 --- a/tests/urcu-asm.c +++ b/tests/urcu-asm.c @@ -20,7 +20,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#include "../urcu.h" +#include void show_read_lock(void) { diff --git a/tests/urcutorture.c b/tests/urcutorture.c index a0aa5dd..9af450d 100644 --- a/tests/urcutorture.c +++ b/tests/urcutorture.c @@ -3,8 +3,8 @@ #include #include #include -#include "../arch_atomic.h" #include "api.h" #define _LGPL_SOURCE -#include "../urcu.h" +#include +#include #include "rcutorture.h" diff --git a/urcu-defer-static.h b/urcu-defer-static.h index 427f3d3..dd875ca 100644 --- a/urcu-defer-static.h +++ b/urcu-defer-static.h @@ -32,8 +32,8 @@ #include #include -#include -#include +#include +#include /* diff --git a/urcu-defer.c b/urcu-defer.c index ccf3511..e71b0cf 100644 --- a/urcu-defer.c +++ b/urcu-defer.c @@ -111,8 +111,8 @@ static void internal_urcu_unlock(pthread_mutex_t *mutex) */ static void wake_up_defer(void) { - if (unlikely(atomic_read(&defer_thread_futex) == -1)) { - atomic_set(&defer_thread_futex, 0); + if (unlikely(uatomic_read(&defer_thread_futex) == -1)) { + uatomic_set(&defer_thread_futex, 0); futex(&defer_thread_futex, FUTEX_WAKE, 1, NULL, NULL, 0); } @@ -137,15 +137,15 @@ static unsigned long rcu_defer_num_callbacks(void) */ static void wait_defer(void) { - atomic_dec(&defer_thread_futex); + uatomic_dec(&defer_thread_futex); smp_mb(); /* Write futex before read queue */ if (rcu_defer_num_callbacks()) { smp_mb(); /* Read queue before write futex */ /* Callbacks are queued, don't wait. */ - atomic_set(&defer_thread_futex, 0); + uatomic_set(&defer_thread_futex, 0); } else { smp_rmb(); /* Read queue before read futex */ - if (atomic_read(&defer_thread_futex) == -1) + if (uatomic_read(&defer_thread_futex) == -1) futex(&defer_thread_futex, FUTEX_WAIT, -1, NULL, NULL, 0); } diff --git a/urcu-qsbr-static.h b/urcu-qsbr-static.h index 87305cb..0d73bcf 100644 --- a/urcu-qsbr-static.h +++ b/urcu-qsbr-static.h @@ -36,8 +36,8 @@ #include #include -#include -#include +#include +#include /* * Identify a shared load. A smp_rmc() or smp_mc() should come before the load. @@ -191,8 +191,8 @@ extern int gp_futex; */ static inline void wake_up_gp(void) { - if (unlikely(atomic_read(&gp_futex) == -1)) { - atomic_set(&gp_futex, 0); + if (unlikely(uatomic_read(&gp_futex) == -1)) { + uatomic_set(&gp_futex, 0); futex(&gp_futex, FUTEX_WAKE, 1, NULL, NULL, 0); } @@ -286,7 +286,7 @@ static inline void _rcu_thread_online(void) if (!__builtin_constant_p(_new) || \ ((_new) != NULL)) \ wmb(); \ - cmpxchg(p, old, _new); \ + uatomic_cmpxchg(p, old, _new); \ }) /** @@ -300,7 +300,7 @@ static inline void _rcu_thread_online(void) if (!__builtin_constant_p(v) || \ ((v) != NULL)) \ wmb(); \ - xchg(p, v); \ + uatomic_xchg(p, v); \ }) /* diff --git a/urcu-qsbr.c b/urcu-qsbr.c index dac6649..f5103ee 100644 --- a/urcu-qsbr.c +++ b/urcu-qsbr.c @@ -106,17 +106,17 @@ static void internal_urcu_unlock(void) */ static void wait_gp(struct reader_registry *index) { - atomic_dec(&gp_futex); + uatomic_dec(&gp_futex); smp_mb(); /* Write futex before read reader_gp */ if (!rcu_gp_ongoing(index->rcu_reader_qs_gp)) { /* Read reader_gp before write futex */ smp_mb(); /* Callbacks are queued, don't wait. */ - atomic_set(&gp_futex, 0); + uatomic_set(&gp_futex, 0); } else { /* Read reader_gp before read futex */ smp_rmb(); - if (atomic_read(&gp_futex) == -1) + if (uatomic_read(&gp_futex) == -1) futex(&gp_futex, FUTEX_WAIT, -1, NULL, NULL, 0); } @@ -287,13 +287,13 @@ void *rcu_assign_pointer_sym(void **p, void *v) void *rcu_cmpxchg_pointer_sym(void **p, void *old, void *_new) { wmb(); - return cmpxchg(p, old, _new); + return uatomic_cmpxchg(p, old, _new); } void *rcu_xchg_pointer_sym(void **p, void *v) { wmb(); - return xchg(p, v); + return uatomic_xchg(p, v); } void *rcu_publish_content_sym(void **p, void *v) diff --git a/urcu-static.h b/urcu-static.h index 3caa0f9..0a23ee5 100644 --- a/urcu-static.h +++ b/urcu-static.h @@ -34,8 +34,8 @@ #include #include -#include -#include +#include +#include /* * Identify a shared load. A smp_rmc() or smp_mc() should come before the load. @@ -227,8 +227,8 @@ extern int gp_futex; */ static inline void wake_up_gp(void) { - if (unlikely(atomic_read(&gp_futex) == -1)) { - atomic_set(&gp_futex, 0); + if (unlikely(uatomic_read(&gp_futex) == -1)) { + uatomic_set(&gp_futex, 0); futex(&gp_futex, FUTEX_WAKE, 1, NULL, NULL, 0); } @@ -323,7 +323,7 @@ static inline void _rcu_read_unlock(void) if (!__builtin_constant_p(_new) || \ ((_new) != NULL)) \ wmb(); \ - cmpxchg(p, old, _new); \ + uatomic_cmpxchg(p, old, _new); \ }) /** @@ -337,7 +337,7 @@ static inline void _rcu_read_unlock(void) if (!__builtin_constant_p(v) || \ ((v) != NULL)) \ wmb(); \ - xchg(p, v); \ + uatomic_xchg(p, v); \ }) /* diff --git a/urcu.c b/urcu.c index 07661a3..b323711 100644 --- a/urcu.c +++ b/urcu.c @@ -211,17 +211,17 @@ static void force_mb_all_threads(void) */ static void wait_gp(struct reader_registry *index) { - atomic_dec(&gp_futex); + uatomic_dec(&gp_futex); force_mb_single_thread(index); /* Write futex before read reader_gp */ if (!rcu_old_gp_ongoing(index->urcu_active_readers)) { /* Read reader_gp before write futex */ force_mb_single_thread(index); /* Callbacks are queued, don't wait. */ - atomic_set(&gp_futex, 0); + uatomic_set(&gp_futex, 0); } else { /* Read reader_gp before read futex */ force_mb_single_thread(index); - if (atomic_read(&gp_futex) == -1) + if (uatomic_read(&gp_futex) == -1) futex(&gp_futex, FUTEX_WAIT, -1, NULL, NULL, 0); } @@ -373,13 +373,13 @@ void *rcu_assign_pointer_sym(void **p, void *v) void *rcu_xchg_pointer_sym(void **p, void *v) { wmb(); - return xchg(p, v); + return uatomic_xchg(p, v); } void *rcu_cmpxchg_pointer_sym(void **p, void *old, void *_new) { wmb(); - return cmpxchg(p, old, _new); + return uatomic_cmpxchg(p, old, _new); } void *rcu_publish_content_sym(void **p, void *v) diff --git a/arch_ppc.h b/urcu/arch_ppc.h similarity index 95% rename from arch_ppc.h rename to urcu/arch_ppc.h index 9c4ec91..8dfd6d1 100644 --- a/arch_ppc.h +++ b/urcu/arch_ppc.h @@ -1,5 +1,5 @@ -#ifndef _ARCH_PPC_H -#define _ARCH_PPC_H +#ifndef _URCU_ARCH_PPC_H +#define _URCU_ARCH_PPC_H /* * arch_ppc.h: trivial definitions for the powerpc architecture. @@ -22,8 +22,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include -#include +#include +#include #define CONFIG_HAVE_FENCE 1 #define CONFIG_HAVE_MEM_COHERENCY @@ -116,4 +116,4 @@ static inline cycles_t get_cycles (void) } } -#endif /* _ARCH_PPC_H */ +#endif /* _URCU_ARCH_PPC_H */ diff --git a/arch_s390.h b/urcu/arch_s390.h similarity index 98% rename from arch_s390.h rename to urcu/arch_s390.h index dba7240..6c69a46 100644 --- a/arch_s390.h +++ b/urcu/arch_s390.h @@ -29,7 +29,7 @@ */ #include -#include +#include #define CONFIG_HAVE_MEM_COHERENCY /* Assume SMP machine, given we don't have this information */ diff --git a/arch_atomic_ppc.h b/urcu/arch_uatomic_ppc.h similarity index 78% rename from arch_atomic_ppc.h rename to urcu/arch_uatomic_ppc.h index 54c5f5c..486b974 100644 --- a/arch_atomic_ppc.h +++ b/urcu/arch_uatomic_ppc.h @@ -1,5 +1,5 @@ -#ifndef _ARCH_ATOMIC_PPC_H -#define _ARCH_ATOMIC_PPC_H +#ifndef _URCU_ARCH_UATOMIC_PPC_H +#define _URCU_ARCH_UATOMIC_PPC_H /* * Copyright (c) 1991-1994 by Xerox Corporation. All rights reserved. @@ -16,11 +16,11 @@ * provided the above notices are retained, and a notice that the code was * modified is included with the above copyright notice. * - * Code inspired from libatomic_ops-1.2, inherited in part from the + * Code inspired from libuatomic_ops-1.2, inherited in part from the * Boehm-Demers-Weiser conservative garbage collector. */ -#include +#include #ifndef __SIZEOF_LONG__ #ifdef __powerpc64__ @@ -38,16 +38,16 @@ #ifndef _INCLUDE_API_H -#define atomic_set(addr, v) \ +#define uatomic_set(addr, v) \ do { \ ACCESS_ONCE(*(addr)) = (v); \ } while (0) -#define atomic_read(addr) ACCESS_ONCE(*(addr)) +#define uatomic_read(addr) ACCESS_ONCE(*(addr)) /* * Using a isync as second barrier for exchange to provide acquire semantic. - * According to atomic_ops/sysdeps/gcc/powerpc.h, the documentation is "fairly + * According to uatomic_ops/sysdeps/gcc/powerpc.h, the documentation is "fairly * explicit that this also has acquire semantics." * Derived from AO_compare_and_swap(), but removed the comparison. */ @@ -55,7 +55,7 @@ do { \ /* xchg */ static inline __attribute__((always_inline)) -unsigned long _atomic_exchange(void *addr, unsigned long val, int len) +unsigned long _uatomic_exchange(void *addr, unsigned long val, int len) { switch (len) { case 4: @@ -99,13 +99,13 @@ unsigned long _atomic_exchange(void *addr, unsigned long val, int len) return 0; } -#define xchg(addr, v) \ - ((__typeof__(*(addr))) _atomic_exchange((addr), (unsigned long)(v), \ +#define uatomic_xchg(addr, v) \ + ((__typeof__(*(addr))) _uatomic_exchange((addr), (unsigned long)(v), \ sizeof(*(addr)))) /* cmpxchg */ static inline __attribute__((always_inline)) -unsigned long _atomic_cmpxchg(void *addr, unsigned long old, +unsigned long _uatomic_cmpxchg(void *addr, unsigned long old, unsigned long _new, int len) { switch (len) { @@ -159,15 +159,15 @@ unsigned long _atomic_cmpxchg(void *addr, unsigned long old, } -#define cmpxchg(addr, old, _new) \ - ((__typeof__(*(addr))) _atomic_cmpxchg((addr), (unsigned long)(old),\ +#define uatomic_cmpxchg(addr, old, _new) \ + ((__typeof__(*(addr))) _uatomic_cmpxchg((addr), (unsigned long)(old),\ (unsigned long)(_new), \ sizeof(*(addr)))) -/* atomic_add_return */ +/* uatomic_add_return */ static inline __attribute__((always_inline)) -unsigned long _atomic_add_return(void *addr, unsigned long val, +unsigned long _uatomic_add_return(void *addr, unsigned long val, int len) { switch (len) { @@ -215,21 +215,21 @@ unsigned long _atomic_add_return(void *addr, unsigned long val, } -#define atomic_add_return(addr, v) \ - ((__typeof__(*(addr))) _atomic_add_return((addr), \ +#define uatomic_add_return(addr, v) \ + ((__typeof__(*(addr))) _uatomic_add_return((addr), \ (unsigned long)(v), \ sizeof(*(addr)))) -/* atomic_sub_return, atomic_add, atomic_sub, atomic_inc, atomic_dec */ +/* uatomic_sub_return, uatomic_add, uatomic_sub, uatomic_inc, uatomic_dec */ -#define atomic_sub_return(addr, v) atomic_add_return((addr), -(v)) +#define uatomic_sub_return(addr, v) uatomic_add_return((addr), -(v)) -#define atomic_add(addr, v) (void)atomic_add_return((addr), (v)) -#define atomic_sub(addr, v) (void)atomic_sub_return((addr), (v)) +#define uatomic_add(addr, v) (void)uatomic_add_return((addr), (v)) +#define uatomic_sub(addr, v) (void)uatomic_sub_return((addr), (v)) -#define atomic_inc(addr) atomic_add((addr), 1) -#define atomic_dec(addr) atomic_add((addr), -1) +#define uatomic_inc(addr) uatomic_add((addr), 1) +#define uatomic_dec(addr) uatomic_add((addr), -1) #endif /* #ifndef _INCLUDE_API_H */ -#endif /* ARCH_ATOMIC_PPC_H */ +#endif /* _URCU_ARCH_UATOMIC_PPC_H */ diff --git a/arch_atomic_s390.h b/urcu/arch_uatomic_s390.h similarity index 80% rename from arch_atomic_s390.h rename to urcu/arch_uatomic_s390.h index 8857d42..c289c74 100644 --- a/arch_atomic_s390.h +++ b/urcu/arch_uatomic_s390.h @@ -1,5 +1,5 @@ -#ifndef _ARCH_ATOMIC_S390_H -#define _ARCH_ATOMIC_S390_H +#ifndef _URCU_ARCH_ATOMIC_S390_H +#define _URCU_ARCH_ATOMIC_S390_H /* * Atomic exchange operations for the S390 architecture. Based on information @@ -40,10 +40,8 @@ #define BITS_PER_LONG (__SIZEOF_LONG__ * 8) #endif -#ifndef _INCLUDE_API_H - static inline __attribute__((always_inline)) -unsigned int atomic_exchange_32(volatile unsigned int *addr, unsigned int val) +unsigned int uatomic_exchange_32(volatile unsigned int *addr, unsigned int val) { unsigned int result; @@ -60,7 +58,7 @@ unsigned int atomic_exchange_32(volatile unsigned int *addr, unsigned int val) #if (BITS_PER_LONG == 64) static inline __attribute__((always_inline)) -unsigned long atomic_exchange_64(volatile unsigned long *addr, +unsigned long uatomic_exchange_64(volatile unsigned long *addr, unsigned long val) { unsigned long result; @@ -78,14 +76,14 @@ unsigned long atomic_exchange_64(volatile unsigned long *addr, #endif static inline __attribute__((always_inline)) -unsigned long _atomic_exchange(volatile void *addr, unsigned long val, int len) +unsigned long _uatomic_exchange(volatile void *addr, unsigned long val, int len) { switch (len) { case 4: - return atomic_exchange_32(addr, val); + return uatomic_exchange_32(addr, val); #if (BITS_PER_LONG == 64) case 8: - return atomic_exchange_64(addr, val); + return uatomic_exchange_64(addr, val); #endif default: __asm__ __volatile__(".long 0xd00d00"); @@ -94,10 +92,8 @@ unsigned long _atomic_exchange(volatile void *addr, unsigned long val, int len) return 0; } -#define xchg(addr, v) \ - (__typeof__(*(addr))) _atomic_exchange((addr), (unsigned long)(v), \ +#define uatomic_xchg(addr, v) \ + (__typeof__(*(addr))) _uatomic_exchange((addr), (unsigned long)(v), \ sizeof(*(addr))) -#endif /* #ifndef _INCLUDE_API_H */ - -#endif /* ARCH_ATOMIC_S390_H */ +#endif /* _URCU_ARCH_ATOMIC_S390_H */ diff --git a/arch_atomic_x86.h b/urcu/arch_uatomic_x86.h similarity index 81% rename from arch_atomic_x86.h rename to urcu/arch_uatomic_x86.h index 3eedc3f..43de9e6 100644 --- a/arch_atomic_x86.h +++ b/urcu/arch_uatomic_x86.h @@ -1,5 +1,5 @@ -#ifndef _ARCH_ATOMIC_X86_H -#define _ARCH_ATOMIC_X86_H +#ifndef _URCU_ARCH_UATOMIC_X86_H +#define _URCU_ARCH_UATOMIC_X86_H /* * Copyright (c) 1991-1994 by Xerox Corporation. All rights reserved. @@ -16,38 +16,36 @@ * provided the above notices are retained, and a notice that the code was * modified is included with the above copyright notice. * - * Code inspired from libatomic_ops-1.2, inherited in part from the + * Code inspired from libuatomic_ops-1.2, inherited in part from the * Boehm-Demers-Weiser conservative garbage collector. */ -#include +#include #ifndef BITS_PER_LONG #define BITS_PER_LONG (__SIZEOF_LONG__ * 8) #endif -#ifndef _INCLUDE_API_H - /* * Derived from AO_compare_and_swap() and AO_test_and_set_full(). */ -struct __atomic_dummy { +struct __uatomic_dummy { unsigned long v[10]; }; -#define __hp(x) ((struct __atomic_dummy *)(x)) +#define __hp(x) ((struct __uatomic_dummy *)(x)) -#define atomic_set(addr, v) \ +#define uatomic_set(addr, v) \ do { \ ACCESS_ONCE(*(addr)) = (v); \ } while (0) -#define atomic_read(addr) ACCESS_ONCE(*(addr)) +#define uatomic_read(addr) ACCESS_ONCE(*(addr)) /* cmpxchg */ static inline __attribute__((always_inline)) -unsigned long _atomic_cmpxchg(void *addr, unsigned long old, +unsigned long _uatomic_cmpxchg(void *addr, unsigned long old, unsigned long _new, int len) { switch (len) { @@ -104,15 +102,15 @@ unsigned long _atomic_cmpxchg(void *addr, unsigned long old, return 0; } -#define cmpxchg(addr, old, _new) \ - ((__typeof__(*(addr))) _atomic_cmpxchg((addr), (unsigned long)(old),\ +#define uatomic_cmpxchg(addr, old, _new) \ + ((__typeof__(*(addr))) _uatomic_cmpxchg((addr), (unsigned long)(old),\ (unsigned long)(_new), \ sizeof(*(addr)))) /* xchg */ static inline __attribute__((always_inline)) -unsigned long _atomic_exchange(void *addr, unsigned long val, int len) +unsigned long _uatomic_exchange(void *addr, unsigned long val, int len) { /* Note: the "xchg" instruction does not need a "lock" prefix. */ switch (len) { @@ -165,14 +163,14 @@ unsigned long _atomic_exchange(void *addr, unsigned long val, int len) return 0; } -#define xchg(addr, v) \ - ((__typeof__(*(addr))) _atomic_exchange((addr), (unsigned long)(v), \ +#define uatomic_xchg(addr, v) \ + ((__typeof__(*(addr))) _uatomic_exchange((addr), (unsigned long)(v), \ sizeof(*(addr)))) -/* atomic_add_return, atomic_sub_return */ +/* uatomic_add_return, uatomic_sub_return */ static inline __attribute__((always_inline)) -unsigned long _atomic_add_return(void *addr, unsigned long val, +unsigned long _uatomic_add_return(void *addr, unsigned long val, int len) { switch (len) { @@ -229,17 +227,17 @@ unsigned long _atomic_add_return(void *addr, unsigned long val, return 0; } -#define atomic_add_return(addr, v) \ - ((__typeof__(*(addr))) _atomic_add_return((addr), \ +#define uatomic_add_return(addr, v) \ + ((__typeof__(*(addr))) _uatomic_add_return((addr), \ (unsigned long)(v), \ sizeof(*(addr)))) -#define atomic_sub_return(addr, v) atomic_add_return((addr), -(v)) +#define uatomic_sub_return(addr, v) uatomic_add_return((addr), -(v)) -/* atomic_add, atomic_sub */ +/* uatomic_add, uatomic_sub */ static inline __attribute__((always_inline)) -void _atomic_add(void *addr, unsigned long val, int len) +void _uatomic_add(void *addr, unsigned long val, int len) { switch (len) { case 1: @@ -287,16 +285,16 @@ void _atomic_add(void *addr, unsigned long val, int len) return; } -#define atomic_add(addr, v) \ - (_atomic_add((addr), (unsigned long)(v), sizeof(*(addr)))) +#define uatomic_add(addr, v) \ + (_uatomic_add((addr), (unsigned long)(v), sizeof(*(addr)))) -#define atomic_sub(addr, v) atomic_add((addr), -(v)) +#define uatomic_sub(addr, v) uatomic_add((addr), -(v)) -/* atomic_inc */ +/* uatomic_inc */ static inline __attribute__((always_inline)) -void _atomic_inc(void *addr, int len) +void _uatomic_inc(void *addr, int len) { switch (len) { case 1: @@ -344,12 +342,12 @@ void _atomic_inc(void *addr, int len) return; } -#define atomic_inc(addr) (_atomic_inc((addr), sizeof(*(addr)))) +#define uatomic_inc(addr) (_uatomic_inc((addr), sizeof(*(addr)))) -/* atomic_dec */ +/* uatomic_dec */ static inline __attribute__((always_inline)) -void _atomic_dec(void *addr, int len) +void _uatomic_dec(void *addr, int len) { switch (len) { case 1: @@ -397,8 +395,6 @@ void _atomic_dec(void *addr, int len) return; } -#define atomic_dec(addr) (_atomic_dec((addr), sizeof(*(addr)))) - -#endif /* #ifndef _INCLUDE_API_H */ +#define uatomic_dec(addr) (_uatomic_dec((addr), sizeof(*(addr)))) -#endif /* ARCH_ATOMIC_X86_H */ +#endif /* _URCU_ARCH_UATOMIC_X86_H */ diff --git a/arch_x86.h b/urcu/arch_x86.h similarity index 96% rename from arch_x86.h rename to urcu/arch_x86.h index 8a57325..29612e0 100644 --- a/arch_x86.h +++ b/urcu/arch_x86.h @@ -1,5 +1,5 @@ -#ifndef _ARCH_X86_H -#define _ARCH_X86_H +#ifndef _URCU_ARCH_X86_H +#define _URCU_ARCH_X86_H /* * arch_x86.h: trivial definitions for the x86 architecture. @@ -22,8 +22,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include -#include +#include +#include /* Assume P4 or newer */ #define CONFIG_HAVE_FENCE 1 @@ -132,4 +132,4 @@ static inline cycles_t get_cycles(void) return ret; } -#endif /* _ARCH_X86_H */ +#endif /* _URCU_ARCH_X86_H */ diff --git a/compiler.h b/urcu/compiler.h similarity index 95% rename from compiler.h rename to urcu/compiler.h index 99972f3..6f6d3e9 100644 --- a/compiler.h +++ b/urcu/compiler.h @@ -1,5 +1,5 @@ -#ifndef _COMPILER_H -#define _COMPILER_H +#ifndef _URCU_COMPILER_H +#define _URCU_COMPILER_H /* * compiler.h @@ -47,4 +47,4 @@ #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) #endif -#endif /* _COMPILER_H */ +#endif /* _URCU_COMPILER_H */ -- 2.34.1