diff options
author | Rainer Gerhards <rgerhards@adiscon.com> | 2010-06-08 08:25:56 +0200 |
---|---|---|
committer | Rainer Gerhards <rgerhards@adiscon.com> | 2010-06-08 08:25:56 +0200 |
commit | 220c57e7ebc49a56cc91fa31308b1563f83a95fb (patch) | |
tree | b4295619e3121daa9766c38b542b15d6c5669760 /runtime/atomic.h | |
parent | d9e64c16e52357bae1eb00fc8403c4e63d6365ca (diff) | |
download | rsyslog-220c57e7ebc49a56cc91fa31308b1563f83a95fb.tar.gz rsyslog-220c57e7ebc49a56cc91fa31308b1563f83a95fb.tar.xz rsyslog-220c57e7ebc49a56cc91fa31308b1563f83a95fb.zip |
bugfix: regression caused more locking action in msg.c than necessary
also: bugfix: mutexes used to similate atomic instructions were not destructed
Diffstat (limited to 'runtime/atomic.h')
-rw-r--r-- | runtime/atomic.h | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/runtime/atomic.h b/runtime/atomic.h index d8cdff7b..e5fafe04 100644 --- a/runtime/atomic.h +++ b/runtime/atomic.h @@ -42,7 +42,7 @@ # define ATOMIC_SUB(data, val, phlpmut) __sync_fetch_and_sub(data, val) # define ATOMIC_ADD(data, val) __sync_fetch_and_add(&(data), val) # define ATOMIC_INC(data, phlpmut) ((void) __sync_fetch_and_add(data, 1)) -# define ATOMIC_INC_AND_FETCH(data) __sync_fetch_and_add(&(data), 1) +# define ATOMIC_INC_AND_FETCH(data, phlpmut) __sync_fetch_and_add(data, 1) # define ATOMIC_DEC(data, phlpmut) ((void) __sync_sub_and_fetch(data, 1)) # define ATOMIC_DEC_AND_FETCH(data, phlpmut) __sync_sub_and_fetch(data, 1) # define ATOMIC_FETCH_32BIT(data, phlpmut) ((unsigned) __sync_fetch_and_and(data, 0xffffffff)) @@ -109,6 +109,15 @@ } static inline int + ATOMIC_INC_AND_FETCH(int *data, pthread_mutex_t *phlpmut) { + int val; + pthread_mutex_lock(phlpmut); + val = ++(*data); + pthread_mutex_unlock(phlpmut); + return(val); + } + + static inline int ATOMIC_DEC_AND_FETCH(int *data, pthread_mutex_t *phlpmut) { int val; pthread_mutex_lock(phlpmut); @@ -139,7 +148,7 @@ #endif # define DEF_ATOMIC_HELPER_MUT(x) pthread_mutex_t x # define INIT_ATOMIC_HELPER_MUT(x) pthread_mutex_init(&(x), NULL) -# define DESTROY_ATOMIC_HELPER_MUT(x) pthread_mutex_init(&(x), NULL) +# define DESTROY_ATOMIC_HELPER_MUT(x) pthread_mutex_destroy(&(x)) # define PREFER_ATOMIC_INC(data) ((void) ++data) |