Merge bitcoin/bitcoin#36057: build: check for SetThreadDescription() at configure time

bed46bd16c build: check for SetThreadDescription() at configure time (ViniciusCestarii)

Pull request description:

  SetThreadDescription() is missing from mingw-w64 headers before 12.0.0, so the Windows cross-compile fails on distro toolchains, e.g. Ubuntu 24.04. Reported by hebasto in https://github.com/bitcoin/bitcoin/pull/35884#issuecomment-5379490348.

  Check for the symbol at configure time and guard its use with a new `HAVE_SETTHREADDESCRIPTION` guard, as cmake/introspection.cmake already does for other optional symbols. This avoids having to declare a minimum mingw-w64 version: toolchains that have the symbol get OS-level thread names, older ones build fine without them.

ACKs for top commit:
  fanquake:
    utACK bed46bd16c - could be reverted + docs updated post branch-off.
  hebasto:
    re-ACK bed46bd16c.

Tree-SHA512: 3edbbd252fc68e976d930a8a6124746b3ba586ea58dc0720a67f8975e935057e2838bb7484d6b789771a327d2b69a092d64f335dd483f90b84a3ef290c138bfb
This commit is contained in:
Hennadii Stepanov
2026-08-27 23:11:24 +01:00
3 changed files with 11 additions and 2 deletions

View File

@@ -76,6 +76,9 @@
/* Define this symbol if you have posix_fallocate */
#cmakedefine HAVE_POSIX_FALLOCATE 1
/* Define this symbol if you have SetThreadDescription */
#cmakedefine HAVE_SETTHREADDESCRIPTION 1
/* Define this symbol if platform supports unix domain sockets */
#cmakedefine HAVE_SOCKADDR_UN 1

View File

@@ -76,6 +76,10 @@ check_cxx_source_compiles("
" HAVE_STRONG_GETAUXVAL
)
# Check for SetThreadDescription(), which is missing from mingw-w64 headers
# before 12.0.0.
check_cxx_symbol_exists(SetThreadDescription "windows.h" HAVE_SETTHREADDESCRIPTION)
# Check for UNIX sockets.
check_cxx_source_compiles("
#include <sys/socket.h>

View File

@@ -2,6 +2,8 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <bitcoin-build-config.h> // IWYU pragma: keep
#include <util/threadnames.h>
#include <util/check.h>
@@ -18,7 +20,7 @@
#include <sys/prctl.h>
#endif
#ifdef WIN32
#ifdef HAVE_SETTHREADDESCRIPTION
#include <windows.h>
#endif
@@ -33,7 +35,7 @@ static void SetThreadName(const char* name)
pthread_set_name_np(pthread_self(), name);
#elif defined(__APPLE__)
pthread_setname_np(name);
#elif defined(WIN32)
#elif defined(HAVE_SETTHREADDESCRIPTION)
// Thread names are ASCII-only, so widening each character is sufficient as
// a conversion to UTF-16.
const std::wstring wname{name, name + std::strlen(name)};