]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
Compatibility fix to add atomic32 support
authorm4tt075 <mgawalter@web.de>
Thu, 15 Jun 2017 08:30:19 +0000 (10:30 +0200)
committerJaroslav Kysela <perex@perex.cz>
Thu, 15 Jun 2017 18:57:42 +0000 (20:57 +0200)
configure
src/atomic.h

index cf62abad8dca1b234188e6ea1205ae87baa63337..b3f6a5242934ece4a1e3db6c26135af56136c978 100755 (executable)
--- a/configure
+++ b/configure
@@ -155,6 +155,11 @@ fi
 check_cc_snippet getloadavg '#include <stdlib.h>
 void test() { getloadavg(NULL,0); }'
 
+check_cc_snippet atomic32 '#include <stdint.h>
+int test(int *ptr){
+return __sync_fetch_and_add(ptr, 1);
+}'
+
 check_cc_snippet atomic64 '#include <stdint.h>
 uint64_t test(uint64_t *ptr){
 return __sync_fetch_and_add(ptr, 1);
index 23c4079cd25b7550f5a3a61706e7600af8ecea8a..402a2861e6697c5b14abe56e506f4684321c3ee1 100644 (file)
@@ -30,7 +30,16 @@ extern pthread_mutex_t atomic_lock;
 static inline int
 atomic_add(volatile int *ptr, int incr)
 {
+#if ENABLE_ATOMIC32
   return __sync_fetch_and_add(ptr, incr);
+#else
+  int ret;
+  pthread_mutex_lock(&atomic_lock);
+  ret = *ptr;
+  *ptr += incr;
+  pthread_mutex_unlock(&atomic_lock);
+  return ret;
+#endif
 }
 
 static inline uint64_t
@@ -144,7 +153,16 @@ atomic_pre_add_s64_peak(volatile int64_t *ptr, int64_t incr,
 static inline int
 atomic_dec(volatile int *ptr, int decr)
 {
+#if ENABLE_ATOMIC32
   return __sync_fetch_and_sub(ptr, decr);
+#else
+  int ret;
+  pthread_mutex_lock(&atomic_lock);
+  ret = *ptr;
+  *ptr -= decr;
+  pthread_mutex_unlock(&atomic_lock);
+  return ret;
+#endif
 }
 
 static inline uint64_t
@@ -184,7 +202,16 @@ atomic_dec_s64(volatile int64_t *ptr, int64_t decr)
 static inline int
 atomic_exchange(volatile int *ptr, int val)
 {
+#if ENABLE_ATOMIC32
   return  __sync_lock_test_and_set(ptr, val);
+#else
+  int ret;
+  pthread_mutex_lock(&atomic_lock);
+  ret = *ptr;
+  *ptr = val;
+  pthread_mutex_unlock(&atomic_lock);
+  return ret;
+#endif
 }
 
 static inline uint64_t