summaryrefslogtreecommitdiffstats
path: root/runtime/atomic.h
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2011-04-12 10:47:09 +0200
committerRainer Gerhards <rgerhards@adiscon.com>2011-04-12 10:47:09 +0200
commit3dbbb21e71b53572d0e5eae106906c161309a3fe (patch)
tree54b96b77725635ad64880ea5cba4187b50c8a3e6 /runtime/atomic.h
parentd5def0d553961eac571e8ca5b6fab5733c851b9f (diff)
parent9348c80744b29fb5f91b5d8edd3f9070f0d0347b (diff)
downloadrsyslog-3dbbb21e71b53572d0e5eae106906c161309a3fe.tar.gz
rsyslog-3dbbb21e71b53572d0e5eae106906c161309a3fe.tar.xz
rsyslog-3dbbb21e71b53572d0e5eae106906c161309a3fe.zip
Merge branch 'v5-beta' into v5-stable
plus bump to new v5-stable Conflicts: ChangeLog configure.ac doc/manual.html
Diffstat (limited to 'runtime/atomic.h')
-rw-r--r--runtime/atomic.h54
1 files changed, 37 insertions, 17 deletions
diff --git a/runtime/atomic.h b/runtime/atomic.h
index 790cb1c6..3e2c0d18 100644
--- a/runtime/atomic.h
+++ b/runtime/atomic.h
@@ -46,7 +46,6 @@
# define ATOMIC_INC(data, phlpmut) ((void) __sync_fetch_and_add(data, 1))
# define ATOMIC_INC_AND_FETCH_int(data, phlpmut) __sync_fetch_and_add(data, 1)
# define ATOMIC_INC_AND_FETCH_unsigned(data, phlpmut) __sync_fetch_and_add(data, 1)
-# define ATOMIC_INC_AND_FETCH_uint64(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))
@@ -160,15 +159,6 @@
return(val);
}
- static inline unsigned
- ATOMIC_INC_AND_FETCH_uint64(uint64 *data, pthread_mutex_t *phlpmut) {
- uint64 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;
@@ -193,13 +183,6 @@
(*data) -= val;
pthread_mutex_unlock(phlpmut);
}
-#if 0
-# warning "atomic builtins not available, using nul operations - rsyslogd will probably be racy!"
-# define ATOMIC_INC_AND_FETCH_int(data) (++(data))
-# define ATOMIC_INC_AND_FETCH_unsigned(data) (++(data))
-# define ATOMIC_INC_AND_FETCH_uint64(data) (++(data))
-# define ATOMIC_STORE_1_TO_32BIT(data) (data) = 1 // TODO: del
-#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_destroy(&(x))
@@ -208,4 +191,41 @@
#endif
+/* we need to handle 64bit atomics seperately as some platforms have
+ * 32 bit atomics, but not 64 biot ones... -- rgerhards, 2010-12-01
+ */
+#ifdef HAVE_ATOMIC_BUILTINS_64BIT
+# define ATOMIC_INC_uint64(data, phlpmut) ((void) __sync_fetch_and_add(data, 1))
+# define ATOMIC_DEC_unit64(data, phlpmut) ((void) __sync_sub_and_fetch(data, 1))
+# define ATOMIC_INC_AND_FETCH_uint64(data, phlpmut) __sync_fetch_and_add(data, 1)
+
+# define DEF_ATOMIC_HELPER_MUT64(x)
+# define INIT_ATOMIC_HELPER_MUT64(x)
+# define DESTROY_ATOMIC_HELPER_MUT64(x)
+#else
+# define ATOMIC_INC_uint64(data, phlpmut) { \
+ pthread_mutex_lock(phlpmut); \
+ ++(*(data)); \
+ pthread_mutex_unlock(phlpmut); \
+ }
+# define ATOMIC_DEC_uint64(data, phlpmut) { \
+ pthread_mutex_lock(phlpmut); \
+ --(*(data)); \
+ pthread_mutex_unlock(phlpmut); \
+ }
+
+ static inline unsigned
+ ATOMIC_INC_AND_FETCH_uint64(uint64 *data, pthread_mutex_t *phlpmut) {
+ uint64 val;
+ pthread_mutex_lock(phlpmut);
+ val = ++(*data);
+ pthread_mutex_unlock(phlpmut);
+ return(val);
+ }
+
+# define DEF_ATOMIC_HELPER_MUT64(x) pthread_mutex_t x
+# define INIT_ATOMIC_HELPER_MUT64(x) pthread_mutex_init(&(x), NULL)
+# define DESTROY_ATOMIC_HELPER_MUT64(x) pthread_mutex_destroy(&(x))
+#endif /* #ifdef HAVE_ATOMIC_BUILTINS_64BIT */
+
#endif /* #ifndef INCLUDED_ATOMIC_H */