Merge bitcoin/bitcoin#30137: build: Remove --enable-threadlocal

17fe948cce build: remove --enable-threadlocal (fanquake)
1e7c20bc19 doc: remove comment about using thread_local (fanquake)
5bba43312c build: Enable `thread_local` for MinGW-w64 builds (Hennadii Stepanov)

Pull request description:

  Includes a commit from #30099.
  Closes #29952.

ACKs for top commit:
  laanwj:
    Code review ACK 17fe948cce
  maflcko:
    utACK 17fe948cce
  hebasto:
    ACK 17fe948cce.
  theuni:
    utACK 17fe948cce

Tree-SHA512: 2aad6d19e79c4d6d7aefd0f41b215ac8d9320f5908808221d78e6ee1c77503832a02759bee2ad397e235b6739e22aca8dcf5c5ef8854deb8c697b18ac56a06da
This commit is contained in:
merge-script 2024-05-21 21:14:30 +01:00
commit 2ec0a28a37
No known key found for this signature in database
GPG key ID: 2EEB9F5CC09526C1
5 changed files with 3 additions and 68 deletions

View file

@ -244,12 +244,6 @@ AC_ARG_ENABLE([lcov-branch-coverage],
[use_lcov_branch=yes],
[use_lcov_branch=no])
AC_ARG_ENABLE([threadlocal],
[AS_HELP_STRING([--enable-threadlocal],
[enable features that depend on the c++ thread_local keyword (currently just thread names in debug logs). (default is to enable if there is platform support)])],
[use_thread_local=$enableval],
[use_thread_local=auto])
AC_ARG_ENABLE([zmq],
[AS_HELP_STRING([--disable-zmq],
[disable ZMQ notifications])],
@ -1028,40 +1022,6 @@ AC_COMPILE_IFELSE([AC_LANG_SOURCE([
[AC_MSG_RESULT([no])]
)
if test "$use_thread_local" = "yes" || test "$use_thread_local" = "auto"; then
TEMP_LDFLAGS="$LDFLAGS"
LDFLAGS="$TEMP_LDFLAGS $PTHREAD_CFLAGS"
AC_MSG_CHECKING([for thread_local support])
AC_LINK_IFELSE([AC_LANG_SOURCE([
#include <thread>
static thread_local int foo = 0;
static void run_thread() { foo++;}
int main(){
for(int i = 0; i < 10; i++) { std::thread(run_thread).detach();}
return foo;
}
])],
[
case $host in
*mingw*)
dnl mingw32's implementation of thread_local has also been shown to behave
dnl erroneously under concurrent usage; see:
dnl https://gist.github.com/jamesob/fe9a872051a88b2025b1aa37bfa98605
AC_MSG_RESULT([no])
;;
*)
AC_DEFINE([HAVE_THREAD_LOCAL], [1], [Define if thread_local is supported.])
AC_MSG_RESULT([yes])
;;
esac
],
[
AC_MSG_RESULT([no])
]
)
LDFLAGS="$TEMP_LDFLAGS"
fi
dnl Check for different ways of gathering OS randomness
AC_MSG_CHECKING([for Linux getrandom function])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[

View file

@ -31,11 +31,7 @@ void AddLoggingArgs(ArgsManager& argsman)
argsman.AddArg("-logips", strprintf("Include IP addresses in debug output (default: %u)", DEFAULT_LOGIPS), ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
argsman.AddArg("-loglevel=<level>|<category>:<level>", strprintf("Set the global or per-category severity level for logging categories enabled with the -debug configuration option or the logging RPC. Possible values are %s (default=%s). The following levels are always logged: error, warning, info. If <category>:<level> is supplied, the setting will override the global one and may be specified multiple times to set multiple category-specific levels. <category> can be: %s.", LogInstance().LogLevelsString(), LogInstance().LogLevelToStr(BCLog::DEFAULT_LOG_LEVEL), LogInstance().LogCategoriesString()), ArgsManager::DISALLOW_NEGATION | ArgsManager::DISALLOW_ELISION | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
argsman.AddArg("-logtimestamps", strprintf("Prepend debug output with timestamp (default: %u)", DEFAULT_LOGTIMESTAMPS), ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
#ifdef HAVE_THREAD_LOCAL
argsman.AddArg("-logthreadnames", strprintf("Prepend debug output with name of the originating thread (only available on platforms supporting thread_local) (default: %u)", DEFAULT_LOGTHREADNAMES), ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
#else
argsman.AddHiddenArgs({"-logthreadnames"});
#endif
argsman.AddArg("-logthreadnames", strprintf("Prepend debug output with name of the originating thread (default: %u)", DEFAULT_LOGTHREADNAMES), ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
argsman.AddArg("-logsourcelocations", strprintf("Prepend debug output with name of the originating source location (source file, line number and function name) (default: %u)", DEFAULT_LOGSOURCELOCATIONS), ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
argsman.AddArg("-logtimemicros", strprintf("Add microsecond precision to debug timestamps (default: %u)", DEFAULT_LOGTIMEMICROS), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
argsman.AddArg("-loglevelalways", strprintf("Always prepend a category and level (default: %u)", DEFAULT_LOGLEVELALWAYS), ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
@ -50,9 +46,7 @@ void SetLoggingOptions(const ArgsManager& args)
LogInstance().m_print_to_console = args.GetBoolArg("-printtoconsole", !args.GetBoolArg("-daemon", false));
LogInstance().m_log_timestamps = args.GetBoolArg("-logtimestamps", DEFAULT_LOGTIMESTAMPS);
LogInstance().m_log_time_micros = args.GetBoolArg("-logtimemicros", DEFAULT_LOGTIMEMICROS);
#ifdef HAVE_THREAD_LOCAL
LogInstance().m_log_threadnames = args.GetBoolArg("-logthreadnames", DEFAULT_LOGTHREADNAMES);
#endif
LogInstance().m_log_sourcelocations = args.GetBoolArg("-logsourcelocations", DEFAULT_LOGSOURCELOCATIONS);
LogInstance().m_always_print_category_level = args.GetBoolArg("-loglevelalways", DEFAULT_LOGLEVELALWAYS);

View file

@ -14,9 +14,8 @@
/**
* This global and the helpers that use it are not thread-safe.
*
* If thread-safety is needed, the global could be made thread_local (given
* that thread_local is supported on all architectures we support) or a
* per-thread instance could be used in the multi-threaded test.
* If thread-safety is needed, a per-thread instance could be
* used in the multi-threaded test.
*/
extern FastRandomContext g_insecure_rand_ctx;

View file

@ -11,8 +11,6 @@
#include <thread>
#include <vector>
#include <config/bitcoin-config.h> // IWYU pragma: keep
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_SUITE(util_threadnames_tests)
@ -52,11 +50,6 @@ std::set<std::string> RenameEnMasse(int num_threads)
*/
BOOST_AUTO_TEST_CASE(util_threadnames_test_rename_threaded)
{
#if !defined(HAVE_THREAD_LOCAL)
// This test doesn't apply to platforms where we don't have thread_local.
return;
#endif
std::set<std::string> names = RenameEnMasse(100);
BOOST_CHECK_EQUAL(names.size(), 100U);

View file

@ -37,10 +37,6 @@ static void SetThreadName(const char* name)
#endif
}
// If we have thread_local, just keep thread ID and name in a thread_local
// global.
#if defined(HAVE_THREAD_LOCAL)
/**
* The name of the thread. We use char array instead of std::string to avoid
* complications with running a destructor when the thread exits. Avoid adding
@ -58,13 +54,6 @@ static void SetInternalName(const std::string& name)
g_thread_name[copy_bytes] = '\0';
}
// Without thread_local available, don't handle internal name at all.
#else
std::string util::ThreadGetInternalName() { return ""; }
static void SetInternalName(const std::string& name) { }
#endif
void util::ThreadRename(const std::string& name)
{
SetThreadName(("b-" + name).c_str());