diff options
author | Rainer Gerhards <rgerhards@adiscon.com> | 2008-09-18 12:19:33 +0200 |
---|---|---|
committer | Rainer Gerhards <rgerhards@adiscon.com> | 2008-09-18 12:19:33 +0200 |
commit | 4c96ebdcfe075e80810b01257cf21ea1c9b3ec0e (patch) | |
tree | b6768398d8d55c04e045b5213e11b952484025e8 /runtime/atomic.h | |
parent | 988989e49ef8639123c83383ba256c4e67679c8d (diff) | |
download | rsyslog-4c96ebdcfe075e80810b01257cf21ea1c9b3ec0e.tar.gz rsyslog-4c96ebdcfe075e80810b01257cf21ea1c9b3ec0e.tar.xz rsyslog-4c96ebdcfe075e80810b01257cf21ea1c9b3ec0e.zip |
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 ;)
Diffstat (limited to 'runtime/atomic.h')
-rw-r--r-- | runtime/atomic.h | 8 |
1 files changed, 6 insertions, 2 deletions
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 */ |