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.

121 lines
4.1 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. @@ -1038,7 +1038,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-1301 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/include/atomic/nolock.h
  73. +++ b/include/atomic/nolock.h
  74. @@ -17,7 +17,7 @@
  75. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
  76. #if defined(__i386__) || defined(_MSC_VER) || defined(__x86_64__) \
  77. - || defined(HAVE_GCC_ATOMIC_BUILTINS) \
  78. + || defined(HAVE_GCC_ATOMIC_BUILTINS) || defined(HAVE_GCC_C11_ATOMICS) \
  79. || defined(HAVE_SOLARIS_ATOMIC)
  80. # ifdef MY_ATOMIC_MODE_DUMMY
  81. @@ -41,7 +41,7 @@
  82. # elif __GNUC__
  83. # if defined(HAVE_SOLARIS_ATOMIC)
  84. # include "solaris.h"
  85. -# elif defined(HAVE_GCC_ATOMIC_BUILTINS)
  86. +# elif defined(HAVE_GCC_ATOMIC_BUILTINS) || defined(HAVE_GCC_C11_ATOMICS)
  87. # include "gcc_builtins.h"
  88. # elif defined(__i386__) || defined(__x86_64__)
  89. # include "x86-gcc.h"
  90. --- a/mysys/CMakeLists.txt
  91. +++ b/mysys/CMakeLists.txt
  92. @@ -78,6 +78,10 @@ IF(HAVE_BFD_H)
  93. TARGET_LINK_LIBRARIES(mysys bfd)
  94. ENDIF(HAVE_BFD_H)
  95. +IF(HAVE_GCC_C11_ATOMICS_WITH_LIBATOMIC)
  96. + TARGET_LINK_LIBRARIES(mysys atomic)
  97. +ENDIF()
  98. +
  99. IF (WIN32)
  100. TARGET_LINK_LIBRARIES(mysys IPHLPAPI)
  101. ENDIF(WIN32)
  102. --- a/sql/CMakeLists.txt
  103. +++ b/sql/CMakeLists.txt
  104. @@ -165,6 +165,10 @@ TARGET_LINK_LIBRARIES(sql ${MYSQLD_STATI
  105. ${SSL_LIBRARIES}
  106. ${LIBSYSTEMD})
  107. +IF(HAVE_GCC_C11_ATOMICS_WITH_LIBATOMIC)
  108. + TARGET_LINK_LIBRARIES(sql atomic)
  109. +ENDIF()
  110. +
  111. IF(WIN32)
  112. SET(MYSQLD_SOURCE main.cc nt_servc.cc message.rc)
  113. TARGET_LINK_LIBRARIES(sql psapi)