1
mirror of https://github.com/jedisct1/libsodium.git synced 2024-12-19 10:05:05 -07:00

Support gcc-like and C11-like memory fences

This commit is contained in:
Frank Denis 2022-03-07 16:47:43 +01:00
parent d4ee08ab8a
commit 69d15f1123
2 changed files with 23 additions and 1 deletions

View File

@ -813,6 +813,26 @@ __sync_lock_release(&_sodium_lock);
AC_DEFINE([HAVE_ATOMIC_OPS], [1], [atomic operations are supported])],
[AC_MSG_RESULT(no)])
AC_MSG_CHECKING(if C11 memory fences are supported)
AC_LINK_IFELSE([AC_LANG_PROGRAM([[
#include <stdatomic.h>
]], [[
atomic_thread_fence(memory_order_acquire);
]]
)],
[AC_MSG_RESULT(yes)
AC_DEFINE([HAVE_C11_MEMORY_FENCES], [1], [C11 memory fences are supported])],
[AC_MSG_RESULT(no)])
AC_MSG_CHECKING(if gcc memory fences are supported)
AC_LINK_IFELSE([AC_LANG_PROGRAM([[ ]], [[
__atomic_thread_fence(__ATOMIC_ACQUIRE);
]]
)],
[AC_MSG_RESULT(yes)
AC_DEFINE([HAVE_GCC_MEMORY_FENCES], [1], [GCC memory fences are supported])],
[AC_MSG_RESULT(no)])
dnl Checks for functions and headers
AC_FUNC_ALLOCA

View File

@ -260,8 +260,10 @@ extern void ct_unpoison(const void *, size_t);
# define UNPOISON(X, L) (void) 0
#endif
#ifdef __ATOMIC_ACQUIRE
#ifdef HAVE_GCC_MEMORY_FENCES
# define ACQUIRE_FENCE __atomic_thread_fence(__ATOMIC_ACQUIRE)
#elif defined(HAVE_C11_MEMORY_FENCES)
# define ACQUIRE_FENCE atomic_thread_fence(memory_order_acquire)
#else
# define ACQUIRE_FENCE (void) 0
#endif