1 #ifndef __ASM_METAG_CMPXCHG_H
2 #define __ASM_METAG_CMPXCHG_H
4 #include <asm/barrier.h>
6 #if defined(CONFIG_METAG_ATOMICITY_IRQSOFF)
7 #include <asm/cmpxchg_irq.h>
8 #elif defined(CONFIG_METAG_ATOMICITY_LOCK1)
9 #include <asm/cmpxchg_lock1.h>
10 #elif defined(CONFIG_METAG_ATOMICITY_LNKGET)
11 #include <asm/cmpxchg_lnkget.h>
14 extern void __xchg_called_with_bad_pointer(void);
16 #define __xchg(ptr, x, size) \
18 unsigned long __xchg__res; \
19 volatile void *__xchg_ptr = (ptr); \
22 __xchg__res = xchg_u32(__xchg_ptr, x); \
25 __xchg__res = xchg_u8(__xchg_ptr, x); \
28 __xchg_called_with_bad_pointer(); \
36 #define xchg(ptr, x) \
37 ((__typeof__(*(ptr)))__xchg((ptr), (unsigned long)(x), sizeof(*(ptr))))
39 /* This function doesn't exist, so you'll get a linker error
40 * if something tries to do an invalid cmpxchg(). */
41 extern void __cmpxchg_called_with_bad_pointer(void);
43 static inline unsigned long __cmpxchg(volatile void *ptr, unsigned long old,
44 unsigned long new, int size)
48 return __cmpxchg_u32(ptr, old, new);
50 __cmpxchg_called_with_bad_pointer();
54 #define __HAVE_ARCH_CMPXCHG 1
56 #define cmpxchg(ptr, o, n) \
58 __typeof__(*(ptr)) _o_ = (o); \
59 __typeof__(*(ptr)) _n_ = (n); \
60 (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_, \
65 #endif /* __ASM_METAG_CMPXCHG_H */