mirror of
https://sourceware.org/git/glibc.git
synced 2024-12-22 19:00:07 +00:00
2003-03-25 Roland McGrath <roland@redhat.com>
* sysdeps/powerpc/bits/atomic.h (__arch_atomic_exchange_32): New macro. (__arch_atomic_exchange_64): New macro. (atomic_exchange): Use them. (__arch_atomic_exchange_and_add_32): New macro. (__arch_atomic_exchange_and_add_64): New macro. (atomic_exchange_and_add): Use them. Original patch from Steven Munroe <sjmunroe@us.ibm.com>.
This commit is contained in:
parent
bacb02966f
commit
3e195d9371
@ -102,16 +102,45 @@ typedef uintmax_t uatomic_max_t;
|
||||
__tmp != 0; \
|
||||
})
|
||||
|
||||
# define __arch_atomic_exchange_64(mem, value) \
|
||||
({ \
|
||||
__typeof (*mem) __val; \
|
||||
__asm __volatile (__ARCH_REL_INSTR "\n" \
|
||||
"1: ldarx %0,0,%2\n" \
|
||||
" stdcx. %3,0,%2\n" \
|
||||
" bne- 1b" \
|
||||
: "=&r" (__val), "=m" (*mem) \
|
||||
: "r" (mem), "r" (value), "1" (*mem) \
|
||||
: "cr0"); \
|
||||
__val; \
|
||||
})
|
||||
|
||||
# define __arch_atomic_exchange_and_add_64(mem, value) \
|
||||
({ \
|
||||
__typeof (*mem) __val, __tmp; \
|
||||
__asm __volatile ("1: ldarx %0,0,%3\n" \
|
||||
" addi %1,%0,%4\n" \
|
||||
" stdcx. %1,0,%3\n" \
|
||||
" bne- 1b" \
|
||||
: "=&b" (__val), "=&r" (__tmp), "=m" (*mem) \
|
||||
: "r" (mem), "I" (value), "2" (*mem) \
|
||||
: "cr0"); \
|
||||
__val; \
|
||||
})
|
||||
|
||||
#else /* powerpc32 */
|
||||
# define __arch_compare_and_exchange_bool_64_acq(mem, newval, oldval) \
|
||||
(abort (), 0)
|
||||
|
||||
# define __arch_atomic_exchange_64(mem, value) \
|
||||
({ abort (); (*mem) = (value); })
|
||||
# define __arch_atomic_exchange_and_add_64(mem, value) \
|
||||
({ abort (); (*mem) = (value); })
|
||||
#endif
|
||||
|
||||
|
||||
#define atomic_exchange(mem, value) \
|
||||
({ if (sizeof (*mem) != 4) \
|
||||
abort (); \
|
||||
int __val; \
|
||||
#define __arch_atomic_exchange_32(mem, value) \
|
||||
({ \
|
||||
__typeof (*mem) __val; \
|
||||
__asm __volatile (__ARCH_REL_INSTR "\n" \
|
||||
"1: lwarx %0,0,%2\n" \
|
||||
" stwcx. %3,0,%2\n" \
|
||||
@ -119,13 +148,12 @@ typedef uintmax_t uatomic_max_t;
|
||||
: "=&r" (__val), "=m" (*mem) \
|
||||
: "r" (mem), "r" (value), "1" (*mem) \
|
||||
: "cr0"); \
|
||||
__val; })
|
||||
__val; \
|
||||
})
|
||||
|
||||
|
||||
#define atomic_exchange_and_add(mem, value) \
|
||||
({ if (sizeof (*mem) != 4) \
|
||||
abort (); \
|
||||
int __val, __tmp; \
|
||||
#define __arch_atomic_exchange_and_add_32(mem, value) \
|
||||
({ \
|
||||
__typeof (*mem) __val, __tmp; \
|
||||
__asm __volatile ("1: lwarx %0,0,%3\n" \
|
||||
" addi %1,%0,%4\n" \
|
||||
" stwcx. %1,0,%3\n" \
|
||||
@ -136,6 +164,30 @@ typedef uintmax_t uatomic_max_t;
|
||||
__val; \
|
||||
})
|
||||
|
||||
#define atomic_exchange(mem, value) \
|
||||
({ \
|
||||
__typeof (*(mem)) __result; \
|
||||
if (sizeof (*mem) == 4) \
|
||||
__result = __arch_atomic_exchange_32 ((mem), (value)); \
|
||||
else if (sizeof (*mem) == 8) \
|
||||
__result = __arch_atomic_exchange_64 ((mem), (value)); \
|
||||
else \
|
||||
abort (); \
|
||||
__result; \
|
||||
})
|
||||
|
||||
#define atomic_exchange_and_add(mem, value) \
|
||||
({ \
|
||||
__typeof (*(mem)) __result; \
|
||||
if (sizeof (*mem) == 4) \
|
||||
__result = __arch_atomic_exchange_and_add_32 ((mem), (value)); \
|
||||
else if (sizeof (*mem) == 8) \
|
||||
__result = __arch_atomic_exchange_and_add_64 ((mem), (value)); \
|
||||
else \
|
||||
abort (); \
|
||||
__result; \
|
||||
})
|
||||
|
||||
|
||||
/* Decrement *MEM if it is > 0, and return the old value. */
|
||||
#define atomic_decrement_if_positive(mem) \
|
||||
@ -156,7 +208,6 @@ typedef uintmax_t uatomic_max_t;
|
||||
})
|
||||
|
||||
|
||||
|
||||
#define atomic_full_barrier() __asm ("sync" ::: "memory")
|
||||
#ifdef __powerpc64__
|
||||
# define atomic_read_barrier() __asm ("lwsync" ::: "memory")
|
||||
|
Loading…
Reference in New Issue
Block a user