[Commits] 46d9d75: Try to fix compile error with __ATOMIC_SEQ_CST

Jan Lindström jan.lindstrom at mariadb.com
Wed Sep 7 20:47:35 EEST 2016


revision-id: 46d9d75674501340bf219d63df271deb01c78969 (mariadb-10.2.1-11-g46d9d75)
parent(s): 34ed6ce9b467ea3650d2dd30b9ea5e03753d386d
committer: Jan Lindström
timestamp: 2016-09-07 20:47:11 +0300
message:

Try to fix compile error with __ATOMIC_SEQ_CST

---
 storage/innobase/include/os0atomic.h | 27 +++++++++++++++++++++++++++
 storage/innobase/innodb.cmake        | 18 ++++++++++++++++++
 2 files changed, 45 insertions(+)

diff --git a/storage/innobase/include/os0atomic.h b/storage/innobase/include/os0atomic.h
index 8e2b06b..4b362e7 100644
--- a/storage/innobase/include/os0atomic.h
+++ b/storage/innobase/include/os0atomic.h
@@ -228,24 +228,36 @@ UNIV_INLINE
 bool
 os_compare_and_swap_ulint(volatile ulint* ptr, ulint old_val, ulint new_val)
 {
+#ifdef HAVE_IB_GCC_ATOMIC_SEQ_CST
   return __atomic_compare_exchange_n(ptr, &old_val, new_val, 0,
                                      __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
+#else
+  return __sync_bool_compare_and_swap(ptr, old_val, new_val);
+#endif
 }
 
 UNIV_INLINE
 bool
 os_compare_and_swap_lint(volatile lint* ptr, lint old_val, lint new_val)
 {
+#ifdef HAVE_IB_GCC_ATOMIC_SEQ_CST
   return __atomic_compare_exchange_n(ptr, &old_val, new_val, 0,
 				     __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
+#else
+  return __sync_bool_compare_and_swap(ptr, old_val, new_val);
+#endif
 }
 
 UNIV_INLINE
 bool
 os_compare_and_swap_uint32(volatile ib_uint32_t* ptr, ib_uint32_t old_val, ib_uint32_t new_val)
 {
+#ifdef HAVE_IB_GCC_ATOMIC_SEQ_CST
   return __atomic_compare_exchange_n(ptr, &old_val, new_val, 0,
                                      __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
+#else
+  return __sync_bool_compare_and_swap(ptr, old_val, new_val);
+#endif
 }
 
 #endif /* HAVE_GCC_SYNC_BUILTINS */
@@ -259,8 +271,12 @@ UNIV_INLINE
 bool
 os_compare_and_swap_thread_id(volatile os_thread_id_t* ptr, os_thread_id_t old_val, os_thread_id_t new_val)
 {
+#ifdef HAVE_IB_GCC_ATOMIC_SEQ_CST
   return __atomic_compare_exchange_n(ptr, &old_val, new_val, 0,
                                      __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
+#else
+  return __sync_bool_compare_and_swap(ptr, old_val, new_val);
+#endif
 }
 #endif /* HAVE_GCC_SYNC_BUILTINS */
 #  define INNODB_RW_LOCKS_USE_ATOMICS
@@ -279,8 +295,14 @@ amount of increment. */
 # define os_atomic_increment(ptr, amount) \
 	__sync_add_and_fetch(ptr, amount)
 #else
+#ifdef HAVE_IB_GCC_ATOMIC_SEQ_CST
 # define os_atomic_increment(ptr, amount) \
 	__atomic_add_fetch(ptr, amount, __ATOMIC_SEQ_CST)
+#else
+# define os_atomic_increment(ptr, amount) \
+	__sync_add_and_fetch(ptr, amount)
+#endif
+
 #endif /* HAVE_GCC_SYNC_BUILTINS */
 
 # define os_atomic_increment_lint(ptr, amount) \
@@ -302,8 +324,13 @@ amount to decrement. */
 # define os_atomic_decrement(ptr, amount) \
 	__sync_sub_and_fetch(ptr, amount)
 #else
+#ifdef HAVE_IB_GCC_ATOMIC_SEQ_CST
 # define os_atomic_decrement(ptr, amount) \
 	__atomic_sub_fetch(ptr, amount, __ATOMIC_SEQ_CST)
+#else
+# define os_atomic_decrement(ptr, amount) \
+	__sync_sub_and_fetch(ptr, amount)
+#endif
 #endif /* HAVE_GCC_SYNC_BUILTINS */
 
 # define os_atomic_decrement_lint(ptr, amount) \
diff --git a/storage/innobase/innodb.cmake b/storage/innobase/innodb.cmake
index ce9e13b..c016f53 100644
--- a/storage/innobase/innodb.cmake
+++ b/storage/innobase/innodb.cmake
@@ -279,6 +279,24 @@ IF(NOT MSVC)
   }"
   HAVE_IB_GCC_ATOMIC_COMPARE_EXCHANGE
   )
+CHECK_C_SOURCE_RUNS(
+  "#include<stdint.h>
+  int main()
+  {
+    unsigned char	a = 0;
+    unsigned char	b = 0;
+    unsigned char	c = 1;
+
+    __atomic_compare_exchange_n(&a, &b, &c, 0,
+			      __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
+    return (0);
+  }"
+  HAVE_IB_GCC_ATOMIC_SEQ_CST
+  )
+
+IF (HAVE_IB_GCC_ATOMIC_SEQ_CST)
+  ADD_DEFINITIONS(-DHAVE_IB_GCC_ATOMIC_CST=1)
+ENDIF()
 
 IF(HAVE_IB_GCC_ATOMIC_BUILTINS)
  ADD_DEFINITIONS(-DHAVE_IB_GCC_ATOMIC_BUILTINS=1)


More information about the commits mailing list