This source file includes following definitions.
- __xchg
1
2
3
4
5
6
7
8 #ifndef _ASM_CMPXCHG_H
9 #define _ASM_CMPXCHG_H
10
11
12
13
14
15
16
17
18
19
20
21
22 static inline unsigned long __xchg(unsigned long x, volatile void *ptr,
23 int size)
24 {
25 unsigned long retval;
26
27
28 if (size != 4) do { asm volatile("brkpt;\n"); } while (1);
29
30 __asm__ __volatile__ (
31 "1: %0 = memw_locked(%1);\n"
32 " memw_locked(%1,P0) = %2;\n"
33 " if (!P0) jump 1b;\n"
34 : "=&r" (retval)
35 : "r" (ptr), "r" (x)
36 : "memory", "p0"
37 );
38 return retval;
39 }
40
41
42
43
44
45 #define xchg(ptr, v) ((__typeof__(*(ptr)))__xchg((unsigned long)(v), (ptr), \
46 sizeof(*(ptr))))
47
48
49
50
51
52
53
54 #define cmpxchg(ptr, old, new) \
55 ({ \
56 __typeof__(ptr) __ptr = (ptr); \
57 __typeof__(*(ptr)) __old = (old); \
58 __typeof__(*(ptr)) __new = (new); \
59 __typeof__(*(ptr)) __oldval = 0; \
60 \
61 asm volatile( \
62 "1: %0 = memw_locked(%1);\n" \
63 " { P0 = cmp.eq(%0,%2);\n" \
64 " if (!P0.new) jump:nt 2f; }\n" \
65 " memw_locked(%1,p0) = %3;\n" \
66 " if (!P0) jump 1b;\n" \
67 "2:\n" \
68 : "=&r" (__oldval) \
69 : "r" (__ptr), "r" (__old), "r" (__new) \
70 : "memory", "p0" \
71 ); \
72 __oldval; \
73 })
74
75 #endif