OSDN Git Service

749100ca47ab2b6202f13fa49b027e7900518ddc
[uclinux-h8/linux.git] / arch / rx / include / asm / cmpxchg.h
1 #ifndef __ARCH_RX_CMPXCHG__
2 #define __ARCH_RX_CMPXCHG__
3
4 #define xchg(ptr, x) \
5         ((__typeof__(*(ptr)))__xchg((unsigned long)(x), (ptr), \
6                                     sizeof(*(ptr))))
7
8 struct __xchg_dummy { unsigned long a[100]; };
9 #define __xg(x) ((volatile struct __xchg_dummy *)(x))
10
11 extern void __bad_xchg_size(void);
12
13 static inline unsigned long __xchg(unsigned long x,
14                                    volatile void *ptr, int size)
15 {
16         switch (size) {
17         case 1:
18                 __asm__ __volatile__
19                         ("xchg %1.b,%0"
20                          : "+r" (x), "+Q" (*__xg(ptr)));
21                 break;
22         case 2:
23                 __asm__ __volatile__
24                         ("xchg %1.w,%0"
25                          : "+r" (x), "+Q" (*__xg(ptr)));
26                 break;
27         case 4:
28                 __asm__ __volatile__
29                         ("xchg %1.l,%0"
30                          : "+r" (x), "+Q" (*__xg(ptr)));
31                 break;
32         default:
33                 __bad_xchg_size();
34         }
35         return x;
36 }
37
38 #include <asm-generic/cmpxchg-local.h>
39
40 /*
41  * cmpxchg_local and cmpxchg64_local are atomic wrt current CPU. Always make
42  * them available.
43  */
44 #define cmpxchg_local(ptr, o, n)                                         \
45         ((__typeof__(*(ptr)))__cmpxchg_local_generic((ptr),              \
46                                                      (unsigned long)(o), \
47                                                      (unsigned long)(n), \
48                                                      sizeof(*(ptr))))
49 #define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
50
51 #ifndef CONFIG_SMP
52 #include <asm-generic/cmpxchg.h>
53 #endif
54
55 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
56
57 #endif /* __ARCH_RX_CMPXCHG__ */