Skip to content

Commit ea7d459

Browse files
committed
Merge bitcoin/bitcoin#36057: build: check for SetThreadDescription() at configure time
bed46bd 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 bitcoin/bitcoin#35884 (comment). 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 bed46bd - could be reverted + docs updated post branch-off. hebasto: re-ACK bed46bd. Tree-SHA512: 3edbbd252fc68e976d930a8a6124746b3ba586ea58dc0720a67f8975e935057e2838bb7484d6b789771a327d2b69a092d64f335dd483f90b84a3ef290c138bfb
2 parents 204256c + bed46bd commit ea7d459

3 files changed

Lines changed: 11 additions & 2 deletions

File tree

cmake/bitcoin-build-config.h.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@
7676
/* Define this symbol if you have posix_fallocate */
7777
#cmakedefine HAVE_POSIX_FALLOCATE 1
7878

79+
/* Define this symbol if you have SetThreadDescription */
80+
#cmakedefine HAVE_SETTHREADDESCRIPTION 1
81+
7982
/* Define this symbol if platform supports unix domain sockets */
8083
#cmakedefine HAVE_SOCKADDR_UN 1
8184

cmake/introspection.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ check_cxx_source_compiles("
7676
" HAVE_STRONG_GETAUXVAL
7777
)
7878

79+
# Check for SetThreadDescription(), which is missing from mingw-w64 headers
80+
# before 12.0.0.
81+
check_cxx_symbol_exists(SetThreadDescription "windows.h" HAVE_SETTHREADDESCRIPTION)
82+
7983
# Check for UNIX sockets.
8084
check_cxx_source_compiles("
8185
#include <sys/socket.h>

src/util/threadnames.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

5+
#include <bitcoin-build-config.h> // IWYU pragma: keep
6+
57
#include <util/threadnames.h>
68
#include <util/check.h>
79

@@ -18,7 +20,7 @@
1820
#include <sys/prctl.h>
1921
#endif
2022

21-
#ifdef WIN32
23+
#ifdef HAVE_SETTHREADDESCRIPTION
2224
#include <windows.h>
2325
#endif
2426

@@ -33,7 +35,7 @@ static void SetThreadName(const char* name)
3335
pthread_set_name_np(pthread_self(), name);
3436
#elif defined(__APPLE__)
3537
pthread_setname_np(name);
36-
#elif defined(WIN32)
38+
#elif defined(HAVE_SETTHREADDESCRIPTION)
3739
// Thread names are ASCII-only, so widening each character is sufficient as
3840
// a conversion to UTF-16.
3941
const std::wstring wname{name, name + std::strlen(name)};

0 commit comments

Comments
 (0)