diff --git a/libc/include/sys/atomics.h b/libc/include/sys/atomics.h index 3ada8def8..143bc4bc2 100644 --- a/libc/include/sys/atomics.h +++ b/libc/include/sys/atomics.h @@ -47,20 +47,20 @@ __BEGIN_DECLS #define __ATOMIC_INLINE__ static __inline__ __attribute__((always_inline)) __ATOMIC_INLINE__ int -__atomic_cmpxchg(int old, int _new, volatile int *ptr) +__atomic_cmpxchg(int old_value, int new_value, volatile int* ptr) { /* We must return 0 on success */ - return __sync_val_compare_and_swap(ptr, old, _new) != old; + return __sync_val_compare_and_swap(ptr, old_value, new_value) != old_value; } __ATOMIC_INLINE__ int -__atomic_swap(int _new, volatile int *ptr) +__atomic_swap(int new_value, volatile int *ptr) { - int prev; + int old_value; do { - prev = *ptr; - } while (__sync_val_compare_and_swap(ptr, prev, _new) != prev); - return prev; + old_value = *ptr; + } while (__sync_val_compare_and_swap(ptr, old_value, new_value) != old_value); + return old_value; } __ATOMIC_INLINE__ int diff --git a/libc/private/bionic_atomic_gcc_builtin.h b/libc/private/bionic_atomic_gcc_builtin.h index e7c57617d..2919f7fef 100644 --- a/libc/private/bionic_atomic_gcc_builtin.h +++ b/libc/private/bionic_atomic_gcc_builtin.h @@ -31,18 +31,17 @@ __ATOMIC_INLINE__ int __bionic_cmpxchg(int32_t old_value, int32_t new_value, volatile int32_t* ptr) { /* We must return 0 on success */ - return __sync_bool_compare_and_swap(ptr, old_value, new_value) == 0; + return __sync_val_compare_and_swap(ptr, old_value, new_value) != old_value; } __ATOMIC_INLINE__ int32_t __bionic_swap(int32_t new_value, volatile int32_t* ptr) { - int32_t prev; + int32_t old_value; do { - prev = *ptr; - status = __sync_val_compare_and_swap(ptr, prev, new_value); - } while (status == 0); - return prev; + old_value = *ptr; + } while (__sync_val_compare_and_swap(ptr, old_value, new_value) != old_value); + return old_value; } __ATOMIC_INLINE__ int32_t