diff --git a/cmake/bitcoin-build-config.h.in b/cmake/bitcoin-build-config.h.in index 1743d79f44d..5e1c1008c2f 100644 --- a/cmake/bitcoin-build-config.h.in +++ b/cmake/bitcoin-build-config.h.in @@ -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 diff --git a/cmake/introspection.cmake b/cmake/introspection.cmake index 612362795a3..a99a7660650 100644 --- a/cmake/introspection.cmake +++ b/cmake/introspection.cmake @@ -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 diff --git a/src/util/threadnames.cpp b/src/util/threadnames.cpp index 2c78fc24a85..4d487c31597 100644 --- a/src/util/threadnames.cpp +++ b/src/util/threadnames.cpp @@ -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 // IWYU pragma: keep + #include #include @@ -18,7 +20,7 @@ #include #endif -#ifdef WIN32 +#ifdef HAVE_SETTHREADDESCRIPTION #include #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)};