Merge "Fix implementation of generic atomic operations"

This commit is contained in:
Elliott Hughes 2012-07-24 17:21:46 -07:00 committed by android code review
commit c98e2365cd
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))
__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

View File

@ -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