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