Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
cmpxchg.h
Go to the documentation of this file.
1 #ifndef _ALPHA_CMPXCHG_H
2 #define _ALPHA_CMPXCHG_H
3 
4 /*
5  * Atomic exchange routines.
6  */
7 
8 #define __ASM__MB
9 #define ____xchg(type, args...) __xchg ## type ## _local(args)
10 #define ____cmpxchg(type, args...) __cmpxchg ## type ## _local(args)
11 #include <asm/xchg.h>
12 
13 #define xchg_local(ptr, x) \
14 ({ \
15  __typeof__(*(ptr)) _x_ = (x); \
16  (__typeof__(*(ptr))) __xchg_local((ptr), (unsigned long)_x_, \
17  sizeof(*(ptr))); \
18 })
19 
20 #define cmpxchg_local(ptr, o, n) \
21 ({ \
22  __typeof__(*(ptr)) _o_ = (o); \
23  __typeof__(*(ptr)) _n_ = (n); \
24  (__typeof__(*(ptr))) __cmpxchg_local((ptr), (unsigned long)_o_, \
25  (unsigned long)_n_, \
26  sizeof(*(ptr))); \
27 })
28 
29 #define cmpxchg64_local(ptr, o, n) \
30 ({ \
31  BUILD_BUG_ON(sizeof(*(ptr)) != 8); \
32  cmpxchg_local((ptr), (o), (n)); \
33 })
34 
35 #ifdef CONFIG_SMP
36 #undef __ASM__MB
37 #define __ASM__MB "\tmb\n"
38 #endif
39 #undef ____xchg
40 #undef ____cmpxchg
41 #define ____xchg(type, args...) __xchg ##type(args)
42 #define ____cmpxchg(type, args...) __cmpxchg ##type(args)
43 #include <asm/xchg.h>
44 
45 #define xchg(ptr, x) \
46 ({ \
47  __typeof__(*(ptr)) _x_ = (x); \
48  (__typeof__(*(ptr))) __xchg((ptr), (unsigned long)_x_, \
49  sizeof(*(ptr))); \
50 })
51 
52 #define cmpxchg(ptr, o, n) \
53 ({ \
54  __typeof__(*(ptr)) _o_ = (o); \
55  __typeof__(*(ptr)) _n_ = (n); \
56  (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_, \
57  (unsigned long)_n_, sizeof(*(ptr)));\
58 })
59 
60 #define cmpxchg64(ptr, o, n) \
61 ({ \
62  BUILD_BUG_ON(sizeof(*(ptr)) != 8); \
63  cmpxchg((ptr), (o), (n)); \
64 })
65 
66 #undef __ASM__MB
67 #undef ____cmpxchg
68 
69 #define __HAVE_ARCH_CMPXCHG 1
70 
71 #endif /* _ALPHA_CMPXCHG_H */