@@ -56,28 +56,6 @@ static inline void name(volatile type *ptr, type v) \
56
56
build_atomic_store (atomic_store , "l" , int , p , v )
57
57
build_atomic_store (atomic_store64 , "q" , long , p , v )
58
58
59
- /*
60
- * #define atomic_set_int(P, V) (*(unsigned int *)(P) |= (V))
61
- */
62
- static inline void atomic_set_int (unsigned int * p , unsigned int v )
63
- {
64
- __asm __volatile (BUS_LOCK "orl %1,%0"
65
- : "+ m " (*p)
66
- : " r " (v)
67
- : " cc ", " memory ");
68
- }
69
-
70
- /*
71
- * #define atomic_clear_int(P, V) (*(unsigned int *)(P) &= ~(V))
72
- */
73
- static inline void atomic_clear_int (unsigned int * p , unsigned int v )
74
- {
75
- __asm __volatile (BUS_LOCK "andl %1,%0"
76
- : "+ m " (*p)
77
- : " r " (~v)
78
- : " cc ", " memory ");
79
- }
80
-
81
59
#define build_atomic_inc (name , size , type , ptr ) \
82
60
static inline void name(type *ptr) \
83
61
{ \
@@ -98,25 +76,27 @@ static inline void name(type *ptr) \
98
76
build_atomic_dec (atomic_dec , "l" , int , p )
99
77
build_atomic_dec (atomic_dec64 , "q" , long , p )
100
78
101
-
102
79
/*
103
- * #define atomic_swap_int(P, V) \
104
- * (return (*(unsigned int *)(P)); *(unsigned int *)(P) = (V);)
80
+ * #define atomic_set_int(P, V) (*(unsigned int *)(P) |= (V))
105
81
*/
106
- static inline int atomic_swap_int (unsigned int * p , unsigned int v )
82
+ static inline void atomic_set_int (unsigned int * p , unsigned int v )
107
83
{
108
- __asm __volatile (BUS_LOCK "xchgl %1,%0"
109
- : "+ m " (*p), " + r " (v)
110
- :
84
+ __asm __volatile (BUS_LOCK "orl %1,%0"
85
+ : "+ m " (*p)
86
+ : " r " (v)
111
87
: " cc ", " memory ");
112
- return v ;
113
88
}
114
89
115
90
/*
116
- * #define atomic_readandclear_int(P) \
117
- * (return (*(unsigned int *)(P)); *(unsigned int *)(P) = 0;)
91
+ * #define atomic_clear_int(P, V) (*(unsigned int *)(P) &= ~(V))
118
92
*/
119
- #define atomic_readandclear_int (p ) atomic_swap_int(p, 0)
93
+ static inline void atomic_clear_int (unsigned int * p , unsigned int v )
94
+ {
95
+ __asm __volatile (BUS_LOCK "andl %1,%0"
96
+ : "+ m " (*p)
97
+ : " r " (~v)
98
+ : " cc ", " memory ");
99
+ }
120
100
121
101
/*
122
102
* #define atomic_set_long(P, V) (*(unsigned long *)(P) |= (V))
@@ -140,37 +120,43 @@ static inline void atomic_clear_long(unsigned long *p, unsigned long v)
140
120
: " cc ", " memory ");
141
121
}
142
122
143
- /*
144
- * #define atomic_swap_long(P, V) \
145
- * (return (*(unsigned long *)(P)); *(unsigned long *)(P) = (V);)
146
- */
147
- static inline long atomic_swap_long (unsigned long * p , unsigned long v )
148
- {
149
- __asm __volatile (BUS_LOCK "xchgq %1,%0"
150
- : "+ m " (*p), " + r " (v)
151
- :
152
- : " cc ", " memory ");
153
- return v ;
123
+ #define build_atomic_swap (name , size , type , ptr , v ) \
124
+ static inline type name (type * ptr , type v ) \
125
+ { \
126
+ asm volatile (BUS_LOCK "xchg" size " %1,%0" \
127
+ : "+m" (* ptr ), "+r" (v ) \
128
+ : \
129
+ : "cc" , "memory" ); \
130
+ return v ; \
154
131
}
155
-
156
- /*
157
- * #define atomic_readandclear_long(P) \
158
- * (return (*(unsigned long *)(P)); *(unsigned long *)(P) = 0;)
159
- */
160
- #define atomic_readandclear_long (p ) atomic_swap_long(p, 0)
161
-
162
- static inline int atomic_cmpxchg_int (unsigned int * p ,
163
- int old , int new )
164
- {
165
- int ret ;
166
-
167
- __asm __volatile (BUS_LOCK "cmpxchgl %2,%1"
168
- : "=a" (ret ), "+m" (* p )
169
- : "r" (new ), "0" (old )
170
- : "memory" );
171
-
172
- return ret ;
132
+ build_atomic_swap (atomic_swap , "l" , int , p , v )
133
+ build_atomic_swap (atomic_swap64 , "q" , long , p , v )
134
+
135
+ /*
136
+ * #define atomic_readandclear(P) \
137
+ * (return (*(int *)(P)); *(int *)(P) = 0;)
138
+ */
139
+ #define atomic_readandclear (p ) atomic_swap(p, 0)
140
+
141
+ /*
142
+ * #define atomic_readandclear64(P) \
143
+ * (return (*(long *)(P)); *(long *)(P) = 0;)
144
+ */
145
+ #define atomic_readandclear64 (p ) atomic_swap64(p, 0)
146
+
147
+ #define build_atomic_cmpxchg (name , size , type , ptr , old , new ) \
148
+ static inline type name(volatile type *ptr, \
149
+ type old, type new) \
150
+ { \
151
+ type ret; \
152
+ asm volatile(BUS_LOCK "cmpxchg" size " %2,%1" \
153
+ : "=a" (ret), "+m" (*p) \
154
+ : "r" (new), "0" (old) \
155
+ : "memory"); \
156
+ return ret; \
173
157
}
158
+ build_atomic_cmpxchg (atomic_cmpxchg , "l" , int , p , old , new )
159
+ build_atomic_cmpxchg (atomic_cmpxchg64 , "q" , long , p , old , new )
174
160
175
161
#define build_atomic_xadd (name , size , type , ptr , v ) \
176
162
static inline type name(type *ptr, type v) \
@@ -196,17 +182,4 @@ build_atomic_xadd(atomic_xadd64, "q", long, p, v)
196
182
#define atomic_inc64_return (v ) atomic_add64_return((v), 1)
197
183
#define atomic_dec64_return (v ) atomic_sub64_return((v), 1)
198
184
199
- static inline int
200
- atomic_cmpset_long (unsigned long * dst , unsigned long expect , unsigned long src )
201
- {
202
- unsigned char res ;
203
-
204
- __asm __volatile (BUS_LOCK "cmpxchg %3,%1\n\tsete %0"
205
- : "=q" (res ), "+m" (* dst ), "+a" (expect )
206
- : "r" (src )
207
- : "memory" , "cc" );
208
-
209
- return res ;
210
- }
211
-
212
185
#endif /* ATOMIC_H*/
0 commit comments