am 860dc7e2: am c98e2365: Merge "Fix implementation of generic atomic operations"

* commit '860dc7e25d4ba64b5bd49fe123bae6e6105dd2e7':
  Fix implementation of generic atomic operations
This commit is contained in:
Elliott Hughes 2012-07-24 18:05:27 -07:00 committed by Android Git Automerger
commit 7c3323516b
2 changed files with 12 additions and 13 deletions

View File

@ -47,20 +47,20 @@ __BEGIN_DECLS
#define __ATOMIC_INLINE__ static __inline__ __attribute__((always_inline)) #define __ATOMIC_INLINE__ static __inline__ __attribute__((always_inline))
__ATOMIC_INLINE__ int __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 */ /* 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_INLINE__ int
__atomic_swap(int _new, volatile int *ptr) __atomic_swap(int new_value, volatile int *ptr)
{ {
int prev; int old_value;
do { do {
prev = *ptr; old_value = *ptr;
} while (__sync_val_compare_and_swap(ptr, prev, _new) != prev); } while (__sync_val_compare_and_swap(ptr, old_value, new_value) != old_value);
return prev; return old_value;
} }
__ATOMIC_INLINE__ int __ATOMIC_INLINE__ int

View File

@ -31,18 +31,17 @@ __ATOMIC_INLINE__ int
__bionic_cmpxchg(int32_t old_value, int32_t new_value, volatile int32_t* ptr) __bionic_cmpxchg(int32_t old_value, int32_t new_value, volatile int32_t* ptr)
{ {
/* We must return 0 on success */ /* 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 __ATOMIC_INLINE__ int32_t
__bionic_swap(int32_t new_value, volatile int32_t* ptr) __bionic_swap(int32_t new_value, volatile int32_t* ptr)
{ {
int32_t prev; int32_t old_value;
do { do {
prev = *ptr; old_value = *ptr;
status = __sync_val_compare_and_swap(ptr, prev, new_value); } while (__sync_val_compare_and_swap(ptr, old_value, new_value) != old_value);
} while (status == 0); return old_value;
return prev;
} }
__ATOMIC_INLINE__ int32_t __ATOMIC_INLINE__ int32_t