You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

112 lines
3.8 KiB

  1. Description: Fix mips missing atomics primitives
  2. On mips we don't have native support for 64bit atomic operations. Make use
  3. of libatomic to emulate them.
  4. Author: Vicențiu Ciorbaru <vicentiu@mariadb.org>
  5. --- a/configure.cmake
  6. +++ b/configure.cmake
  7. @@ -128,7 +128,7 @@ IF(UNIX)
  8. ENDIF()
  9. FIND_PACKAGE(Threads)
  10. - SET(CMAKE_REQUIRED_LIBRARIES
  11. + LIST(APPEND CMAKE_REQUIRED_LIBRARIES
  12. ${LIBM} ${LIBNSL} ${LIBBIND} ${LIBCRYPT} ${LIBSOCKET} ${LIBDL} ${CMAKE_THREAD_LIBS_INIT} ${LIBRT} ${LIBEXECINFO})
  13. # Need explicit pthread for gcc -fsanitize=address
  14. IF(CMAKE_USE_PTHREADS_INIT AND CMAKE_C_FLAGS MATCHES "-fsanitize=")
  15. @@ -952,7 +952,26 @@ ELSEIF(NOT WITH_ATOMIC_OPS)
  16. long long int *ptr= &var;
  17. return (int)__atomic_load_n(ptr, __ATOMIC_SEQ_CST);
  18. }"
  19. - HAVE_GCC_C11_ATOMICS)
  20. + HAVE_GCC_C11_ATOMICS_WITHOUT_LIBATOMIC)
  21. + IF(HAVE_GCC_C11_ATOMICS_WITHOUT_LIBATOMIC)
  22. + SET(HAVE_GCC_C11_ATOMICS True)
  23. + ELSE()
  24. + SET(OLD_CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
  25. + LIST(APPEND CMAKE_REQUIRED_LIBRARIES "atomic")
  26. + CHECK_CXX_SOURCE_COMPILES("
  27. + int main()
  28. + {
  29. + long long int var= 1;
  30. + long long int *ptr= &var;
  31. + return (int)__atomic_load_n(ptr, __ATOMIC_SEQ_CST);
  32. + }"
  33. + HAVE_GCC_C11_ATOMICS_WITH_LIBATOMIC)
  34. + IF(HAVE_GCC_C11_ATOMICS_WITH_LIBATOMIC)
  35. + SET(HAVE_GCC_C11_ATOMICS True)
  36. + ELSE()
  37. + SET(CMAKE_REQUIRED_LIBRARIES ${OLD_CMAKE_REQUIRED_LIBRARIES})
  38. + ENDIF()
  39. + ENDIF()
  40. ELSE()
  41. MESSAGE(FATAL_ERROR "${WITH_ATOMIC_OPS} is not a valid value for WITH_ATOMIC_OPS!")
  42. ENDIF()
  43. --- a/include/atomic/gcc_builtins.h
  44. +++ b/include/atomic/gcc_builtins.h
  45. @@ -16,6 +16,7 @@
  46. along with this program; if not, write to the Free Software
  47. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */
  48. +#if defined (HAVE_GCC_ATOMIC_BUILTINS)
  49. #define make_atomic_add_body(S) \
  50. v= __sync_fetch_and_add(a, v);
  51. #define make_atomic_fas_body(S) \
  52. @@ -26,6 +27,20 @@
  53. sav= __sync_val_compare_and_swap(a, cmp_val, set);\
  54. if (!(ret= (sav == cmp_val))) *cmp= sav
  55. +#elif defined(HAVE_GCC_C11_ATOMICS)
  56. +
  57. +#define make_atomic_add_body(S) \
  58. + v= __atomic_fetch_add(a, v, __ATOMIC_SEQ_CST)
  59. +#define make_atomic_fas_body(S) \
  60. + v= __atomic_exchange_n(a, v, __ATOMIC_SEQ_CST)
  61. +#define make_atomic_cas_body(S) \
  62. + int ## S sav; \
  63. + ret= __atomic_compare_exchange_n(a, cmp, set, \
  64. + 0, \
  65. + __ATOMIC_SEQ_CST,\
  66. + __ATOMIC_SEQ_CST);
  67. +#endif
  68. +
  69. #ifdef MY_ATOMIC_MODE_DUMMY
  70. #define make_atomic_load_body(S) ret= *a
  71. #define make_atomic_store_body(S) *a= v
  72. --- a/mysys/CMakeLists.txt
  73. +++ b/mysys/CMakeLists.txt
  74. @@ -81,6 +81,10 @@ IF(HAVE_BFD_H)
  75. TARGET_LINK_LIBRARIES(mysys bfd)
  76. ENDIF(HAVE_BFD_H)
  77. +IF(HAVE_GCC_C11_ATOMICS_WITH_LIBATOMIC)
  78. + TARGET_LINK_LIBRARIES(mysys atomic)
  79. +ENDIF()
  80. +
  81. IF (WIN32)
  82. TARGET_LINK_LIBRARIES(mysys IPHLPAPI)
  83. ENDIF(WIN32)
  84. --- a/sql/CMakeLists.txt
  85. +++ b/sql/CMakeLists.txt
  86. @@ -170,6 +170,10 @@ TARGET_LINK_LIBRARIES(sql ${MYSQLD_STATI
  87. ${SSL_LIBRARIES}
  88. ${LIBSYSTEMD})
  89. +IF(HAVE_GCC_C11_ATOMICS_WITH_LIBATOMIC)
  90. + TARGET_LINK_LIBRARIES(sql atomic)
  91. +ENDIF()
  92. +
  93. IF(WIN32)
  94. SET(MYSQLD_SOURCE main.cc nt_servc.cc message.rc)
  95. TARGET_LINK_LIBRARIES(sql psapi)
  96. --- a/include/my_atomic.h
  97. +++ b/include/my_atomic.h
  98. @@ -126,7 +126,7 @@
  99. #include "atomic/generic-msvc.h"
  100. #elif defined(HAVE_SOLARIS_ATOMIC)
  101. #include "atomic/solaris.h"
  102. -#elif defined(HAVE_GCC_ATOMIC_BUILTINS)
  103. +#elif defined(HAVE_GCC_ATOMIC_BUILTINS) || defined(HAVE_GCC_C11_ATOMICS)
  104. #include "atomic/gcc_builtins.h"
  105. #elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
  106. #include "atomic/x86-gcc.h"