11/*****************************************************************************
2- Copyright (c) 1995, 2015 , Oracle and/or its affiliates. All Rights Reserved.
2+ Copyright (c) 1995, 2016 , Oracle and/or its affiliates. All Rights Reserved.
33Copyright (c) 2008, Google Inc.
44
55Portions of this file contain modifications contributed and copyrighted by
@@ -208,6 +208,8 @@ amount to decrement. There is no atomic substract function on Windows */
208208Returns true if swapped, ptr is pointer to target, old_val is value to
209209compare to, new_val is the value to swap in. */
210210
211+ #if defined(HAVE_GCC_SYNC_BUILTINS )
212+
211213# define os_compare_and_swap (ptr , old_val , new_val ) \
212214 __sync_bool_compare_and_swap(ptr, old_val, new_val)
213215
@@ -220,9 +222,47 @@ compare to, new_val is the value to swap in. */
220222# define os_compare_and_swap_uint32 (ptr , old_val , new_val ) \
221223 os_compare_and_swap(ptr, old_val, new_val)
222224
225+ #else
226+
227+ UNIV_INLINE
228+ bool
229+ os_compare_and_swap_ulint (volatile ulint * ptr , ulint old_val , ulint new_val )
230+ {
231+ return __atomic_compare_exchange_n (ptr , & old_val , new_val , 0 ,
232+ __ATOMIC_SEQ_CST , __ATOMIC_SEQ_CST );
233+ }
234+
235+ UNIV_INLINE
236+ bool
237+ os_compare_and_swap_lint (volatile lint * ptr , lint old_val , lint new_val )
238+ {
239+ return __atomic_compare_exchange_n (ptr , & old_val , new_val , 0 ,
240+ __ATOMIC_SEQ_CST , __ATOMIC_SEQ_CST );
241+ }
242+
243+ UNIV_INLINE
244+ bool
245+ os_compare_and_swap_uint32 (volatile ib_uint32_t * ptr , ib_uint32_t old_val , ib_uint32_t new_val )
246+ {
247+ return __atomic_compare_exchange_n (ptr , & old_val , new_val , 0 ,
248+ __ATOMIC_SEQ_CST , __ATOMIC_SEQ_CST );
249+ }
250+
251+ #endif /* HAVE_GCC_SYNC_BUILTINS */
252+
223253# ifdef HAVE_IB_ATOMIC_PTHREAD_T_GCC
254+ #if defined(HAVE_GCC_SYNC_BUILTINS )
224255# define os_compare_and_swap_thread_id (ptr , old_val , new_val ) \
225256 os_compare_and_swap(ptr, old_val, new_val)
257+ #else
258+ UNIV_INLINE
259+ bool
260+ os_compare_and_swap_thread_id (volatile os_thread_id_t * ptr , os_thread_id_t old_val , os_thread_id_t new_val )
261+ {
262+ return __atomic_compare_exchange_n (ptr , & old_val , new_val , 0 ,
263+ __ATOMIC_SEQ_CST , __ATOMIC_SEQ_CST );
264+ }
265+ #endif /* HAVE_GCC_SYNC_BUILTINS */
226266# define INNODB_RW_LOCKS_USE_ATOMICS
227267# define IB_ATOMICS_STARTUP_MSG \
228268 "Mutexes and rw_locks use GCC atomic builtins"
@@ -235,8 +275,13 @@ compare to, new_val is the value to swap in. */
235275Returns the resulting value, ptr is pointer to target, amount is the
236276amount of increment. */
237277
278+ #if defined(HAVE_GCC_SYNC_BUILTINS )
238279# define os_atomic_increment (ptr , amount ) \
239280 __sync_add_and_fetch(ptr, amount)
281+ #else
282+ # define os_atomic_increment (ptr , amount ) \
283+ __atomic_add_fetch(ptr, amount, __ATOMIC_SEQ_CST)
284+ #endif /* HAVE_GCC_SYNC_BUILTINS */
240285
241286# define os_atomic_increment_lint (ptr , amount ) \
242287 os_atomic_increment(ptr, amount)
@@ -253,8 +298,13 @@ amount of increment. */
253298/* Returns the resulting value, ptr is pointer to target, amount is the
254299amount to decrement. */
255300
301+ #if defined(HAVE_GCC_SYNC_BUILTINS )
256302# define os_atomic_decrement (ptr , amount ) \
257303 __sync_sub_and_fetch(ptr, amount)
304+ #else
305+ # define os_atomic_decrement (ptr , amount ) \
306+ __atomic_sub_fetch(ptr, amount, __ATOMIC_SEQ_CST)
307+ #endif /* HAVE_GCC_SYNC_BUILTINS */
258308
259309# define os_atomic_decrement_lint (ptr , amount ) \
260310 os_atomic_decrement(ptr, amount)
0 commit comments