221
222 inline void Atomic::dec_ptr(volatile intptr_t* dest) {
223 add_ptr(-1, dest);
224 }
225
226 inline void Atomic::dec_ptr(volatile void* dest) {
227 add_ptr(-1, dest);
228 }
229
230 inline jint Atomic::xchg(jint exchange_value, volatile jint* dest) {
231 #ifdef ARM
232 return arm_lock_test_and_set(dest, exchange_value);
233 #else
234 #ifdef M68K
235 return m68k_lock_test_and_set(dest, exchange_value);
236 #else
237 // __sync_lock_test_and_set is a bizarrely named atomic exchange
238 // operation. Note that some platforms only support this with the
239 // limitation that the only valid value to store is the immediate
240 // constant 1. There is a test for this in JNI_CreateJavaVM().
241 return __sync_lock_test_and_set (dest, exchange_value);
242 #endif // M68K
243 #endif // ARM
244 }
245
246 inline intptr_t Atomic::xchg_ptr(intptr_t exchange_value,
247 volatile intptr_t* dest) {
248 #ifdef ARM
249 return arm_lock_test_and_set(dest, exchange_value);
250 #else
251 #ifdef M68K
252 return m68k_lock_test_and_set(dest, exchange_value);
253 #else
254 return __sync_lock_test_and_set (dest, exchange_value);
255 #endif // M68K
256 #endif // ARM
257 }
258
259 inline void* Atomic::xchg_ptr(void* exchange_value, volatile void* dest) {
260 return (void *) xchg_ptr((intptr_t) exchange_value,
261 (volatile intptr_t*) dest);
262 }
263
264 inline jint Atomic::cmpxchg(jint exchange_value,
265 volatile jint* dest,
266 jint compare_value) {
267 #ifdef ARM
268 return arm_compare_and_swap(dest, compare_value, exchange_value);
269 #else
270 #ifdef M68K
271 return m68k_compare_and_swap(dest, compare_value, exchange_value);
272 #else
273 return __sync_val_compare_and_swap(dest, compare_value, exchange_value);
274 #endif // M68K
|
221
222 inline void Atomic::dec_ptr(volatile intptr_t* dest) {
223 add_ptr(-1, dest);
224 }
225
226 inline void Atomic::dec_ptr(volatile void* dest) {
227 add_ptr(-1, dest);
228 }
229
230 inline jint Atomic::xchg(jint exchange_value, volatile jint* dest) {
231 #ifdef ARM
232 return arm_lock_test_and_set(dest, exchange_value);
233 #else
234 #ifdef M68K
235 return m68k_lock_test_and_set(dest, exchange_value);
236 #else
237 // __sync_lock_test_and_set is a bizarrely named atomic exchange
238 // operation. Note that some platforms only support this with the
239 // limitation that the only valid value to store is the immediate
240 // constant 1. There is a test for this in JNI_CreateJavaVM().
241 jint result = __sync_lock_test_and_set (dest, exchange_value);
242 // All atomic operations are expected to be full memory barriers
243 // (see atomic.hpp). However, __sync_lock_test_and_set is not
244 // a full memory barrier, but an acquire barrier. Hence, this added
245 // barrier.
246 __sync_synchronize();
247 return result;
248 #endif // M68K
249 #endif // ARM
250 }
251
252 inline intptr_t Atomic::xchg_ptr(intptr_t exchange_value,
253 volatile intptr_t* dest) {
254 #ifdef ARM
255 return arm_lock_test_and_set(dest, exchange_value);
256 #else
257 #ifdef M68K
258 return m68k_lock_test_and_set(dest, exchange_value);
259 #else
260 intptr_t result = __sync_lock_test_and_set (dest, exchange_value);
261 __sync_synchronize();
262 return result;
263 #endif // M68K
264 #endif // ARM
265 }
266
267 inline void* Atomic::xchg_ptr(void* exchange_value, volatile void* dest) {
268 return (void *) xchg_ptr((intptr_t) exchange_value,
269 (volatile intptr_t*) dest);
270 }
271
272 inline jint Atomic::cmpxchg(jint exchange_value,
273 volatile jint* dest,
274 jint compare_value) {
275 #ifdef ARM
276 return arm_compare_and_swap(dest, compare_value, exchange_value);
277 #else
278 #ifdef M68K
279 return m68k_compare_and_swap(dest, compare_value, exchange_value);
280 #else
281 return __sync_val_compare_and_swap(dest, compare_value, exchange_value);
282 #endif // M68K
|