Skip to content

Commit

Permalink
build: Check for std::atomic::exchange rather than std::atomic_exchange
Browse files Browse the repository at this point in the history
Our usage of std::atomic is with it's own exchange function, not
std::atomic_exchange. So we should be looking specifically for that
function.

Additionally, -pthread and -lpthread have an effect on whether -latomic
will be needed, so the atomics check needs to use these flags as well.
This will make the flags in use better match what is actually used when
linking.

This removes the need for -latomic for riscv builds, which resolves a
guix cross architecture reproducibility issue.
  • Loading branch information
achow101 committed Jul 18, 2022
1 parent c92eb6c commit 4de4221
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 4 additions & 1 deletion build-aux/m4/l_atomic.m4
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ m4_define([_CHECK_ATOMIC_testbody], [[
int main() {
std::atomic<bool> lock{true};
std::atomic_exchange(&lock, false);
lock.exchange(false);
std::atomic<std::chrono::seconds> t{0s};
t.store(2s);
Expand All @@ -34,6 +34,8 @@ m4_define([_CHECK_ATOMIC_testbody], [[
AC_DEFUN([CHECK_ATOMIC], [
AC_LANG_PUSH(C++)
TEMP_CXXFLAGS="$CXXFLAGS"
CXXFLAGS="$CXXFLAGS $PTHREAD_CFLAGS"
AC_MSG_CHECKING([whether std::atomic can be used without link library])
Expand All @@ -51,5 +53,6 @@ AC_DEFUN([CHECK_ATOMIC], [
])
])
CXXFLAGS="$TEMP_CXXFLAGS"
AC_LANG_POP
])
6 changes: 3 additions & 3 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,6 @@ else
AX_CXX_COMPILE_STDCXX([20], [noext], [mandatory])
fi

dnl Check if -latomic is required for <std::atomic>
CHECK_ATOMIC

dnl check if additional link flags are required for std::filesystem
CHECK_FILESYSTEM

Expand Down Expand Up @@ -887,6 +884,9 @@ AC_C_BIGENDIAN
dnl Check for pthread compile/link requirements
AX_PTHREAD

dnl Check if -latomic is required for <std::atomic>
CHECK_ATOMIC

dnl The following macro will add the necessary defines to bitcoin-config.h, but
dnl they also need to be passed down to any subprojects. Pull the results out of
dnl the cache and add them to CPPFLAGS.
Expand Down

0 comments on commit 4de4221

Please sign in to comment.