From: m4tt075 Date: Thu, 15 Jun 2017 08:30:19 +0000 (+0200) Subject: Compatibility fix to add atomic32 support X-Git-Tag: v4.2.3~32 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4e77d2a8bfcc339af77dc8a9b068ae9dd481025a;p=thirdparty%2Ftvheadend.git Compatibility fix to add atomic32 support --- diff --git a/configure b/configure index cf62abad8..b3f6a5242 100755 --- a/configure +++ b/configure @@ -155,6 +155,11 @@ fi check_cc_snippet getloadavg '#include void test() { getloadavg(NULL,0); }' +check_cc_snippet atomic32 '#include +int test(int *ptr){ +return __sync_fetch_and_add(ptr, 1); +}' + check_cc_snippet atomic64 '#include uint64_t test(uint64_t *ptr){ return __sync_fetch_and_add(ptr, 1); diff --git a/src/atomic.h b/src/atomic.h index 23c4079cd..402a2861e 100644 --- a/src/atomic.h +++ b/src/atomic.h @@ -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