From 988989e49ef8639123c83383ba256c4e67679c8d Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Thu, 18 Sep 2008 10:49:16 +0200 Subject: re-enabled gcc builtin atomic operations and added a proper ./configure check --- runtime/atomic.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'runtime/atomic.h') diff --git a/runtime/atomic.h b/runtime/atomic.h index 430ae7f0..d6811628 100644 --- a/runtime/atomic.h +++ b/runtime/atomic.h @@ -1,6 +1,6 @@ /* This header supplies atomic operations. So far, we rely on GCC's - * atomic builtins. I have no idea if we can check them via autotools, - * but I am making the necessary provisioning to live without them if + * atomic builtins. During configure, we check if atomic operatons are + * available. If they are not, I am making the necessary provisioning to live without them if * they are not available. Please note that you should only use the macros * here if you think you can actually live WITHOUT an explicit atomic operation, * because in the non-presence of them, we simply do it without atomicitiy. @@ -36,16 +36,16 @@ #ifndef INCLUDED_ATOMIC_H #define INCLUDED_ATOMIC_H -/* set the following to 1 if we have atomic operations (and #undef it otherwise) */ -/* #define DO_HAVE_ATOMICS 1 */ /* for this release, we disable atomic calls because there seem to be some * portability problems and we can not fix that without destabilizing the build. * They simply came in too late. -- rgerhards, 2008-04-02 */ -/* make sure they are not used! -#define ATOMIC_INC(data) ((void) __sync_fetch_and_add(&data, 1)) -#define ATOMIC_DEC_AND_FETCH(data) __sync_sub_and_fetch(&data, 1) -*/ -#define ATOMIC_INC(data) (++(data)) +#ifdef HAVE_ATOMIC_BUILTINS +# define ATOMIC_INC(data) ((void) __sync_fetch_and_add(&data, 1)) +# define ATOMIC_DEC_AND_FETCH(data) __sync_sub_and_fetch(&data, 1) +#else +# warning "atomic builtins not available, using nul operations" +# define ATOMIC_INC(data) (++(data)) +#endif #endif /* #ifndef INCLUDED_ATOMIC_H */ -- cgit v1.2.3 From 4c96ebdcfe075e80810b01257cf21ea1c9b3ec0e Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Thu, 18 Sep 2008 12:19:33 +0200 Subject: bugfix: potential race condition when adding messages to queue There was a wrong order of mutex lock operations. It is hard to believe that really caused problems, but in theory it could and with threading we often see that theory becomes practice if something is only used long enough on a fast enough machine with enough CPUs ;) --- runtime/atomic.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'runtime/atomic.h') diff --git a/runtime/atomic.h b/runtime/atomic.h index d6811628..d15f78ee 100644 --- a/runtime/atomic.h +++ b/runtime/atomic.h @@ -41,11 +41,15 @@ * They simply came in too late. -- rgerhards, 2008-04-02 */ #ifdef HAVE_ATOMIC_BUILTINS -# define ATOMIC_INC(data) ((void) __sync_fetch_and_add(&data, 1)) -# define ATOMIC_DEC_AND_FETCH(data) __sync_sub_and_fetch(&data, 1) +# define ATOMIC_INC(data) ((void) __sync_fetch_and_add(&(data), 1)) +# define ATOMIC_DEC_AND_FETCH(data) __sync_sub_and_fetch(&(data), 1) +# define ATOMIC_FETCH_32BIT(data) ((unsigned) __sync_fetch_and_and(&(data), 0xffffffff)) +# define ATOMIC_STORE_1_TO_32BIT(data) __sync_lock_test_and_set(&(data), 1) #else # warning "atomic builtins not available, using nul operations" # define ATOMIC_INC(data) (++(data)) +# define ATOMIC_FETCH_32BIT(data) (data) +# define ATOMIC_STORE_1_TO_32BIT(data) (data) = 1 #endif #endif /* #ifndef INCLUDED_ATOMIC_H */ -- cgit v1.2.3 From bc70a730194759e85f9c3641573c46b4a8476198 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Fri, 19 Sep 2008 17:41:11 +0200 Subject: bugfix: proper synchronization on message destruction The code was potentially race, at least on systems where a memory barrier was needed. Fix not fully tested yet. --- runtime/atomic.h | 1 + 1 file changed, 1 insertion(+) (limited to 'runtime/atomic.h') diff --git a/runtime/atomic.h b/runtime/atomic.h index d15f78ee..2dbe7f52 100644 --- a/runtime/atomic.h +++ b/runtime/atomic.h @@ -48,6 +48,7 @@ #else # warning "atomic builtins not available, using nul operations" # define ATOMIC_INC(data) (++(data)) +# define ATOMIC_DEC_AND_FETCH(data) (--(data)) # define ATOMIC_FETCH_32BIT(data) (data) # define ATOMIC_STORE_1_TO_32BIT(data) (data) = 1 #endif -- cgit v1.2.3