Merge pull request #10641 from brad0/netbsd_pthread_setname_np
Some checks are pending
Container Image / Container Image (push) Waiting to run
Linux / alpine:bash (push) Waiting to run
Linux / amazonlinux:2 (push) Waiting to run
Linux / amazonlinux:2023 (push) Waiting to run
Linux / debian:11 (linux/386) (push) Waiting to run
Linux / debian:11 (push) Waiting to run
Linux / debian:12 (linux/386) (push) Waiting to run
Linux / debian:12 (push) Waiting to run
Linux / debian:13 (push) Waiting to run
Linux / fedora:41 (push) Waiting to run
Linux / fedora:42 (push) Waiting to run
Linux / opensuse/leap:15.6 (push) Waiting to run
Linux / opensuse/leap:16.0 (push) Waiting to run
Linux / registry.suse.com/suse/sle15:15.6 (push) Waiting to run
Linux / registry.suse.com/suse/sle15:15.7 (push) Waiting to run
Linux / rockylinux/rockylinux:10 (push) Waiting to run
Linux / rockylinux:8 (push) Waiting to run
Linux / rockylinux:9 (push) Waiting to run
Linux / ubuntu:22.04 (push) Waiting to run
Linux / ubuntu:24.04 (push) Waiting to run
Linux / ubuntu:25.04 (push) Waiting to run
Linux / ubuntu:25.10 (push) Waiting to run
Windows / Windows (push) Waiting to run

Fix usage of pthread_setname_np() on NetBSD
This commit is contained in:
Alvar 2025-11-27 17:12:17 +00:00 committed by GitHub
commit 50b289a7a2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1311,6 +1311,23 @@ void Utility::SetThreadName(const String& name, bool os)
{
m_ThreadName.reset(new String(name));
#if defined(HAVE_PTHREAD_SET_NAME_NP) || defined(HAVE_PTHREAD_SETNAME_NP)
unsigned int len;
/* https://github.com/llvm/llvm-project/blob/6412184891526690cff804f87f986b1fa039f011/llvm/lib/Support/Unix/Threading.inc#L157 */
# ifdef PTHREAD_MAX_NAMELEN_NP
len = PTHREAD_MAX_NAMELEN_NP;
# elif defined(__APPLE__) /* PTHREAD_MAX_NAMELEN_NP */
len = 64;
# elif defined(__OpenBSD__) /* __APPLE__ */
len = 24;
# else /* __OpenBSD__ */
len = 16;
# endif /* PTHREAD_MAX_NAMELEN_NP */
String tname = name.SubStr(0, len - 1);
#endif
if (!os)
return;
@ -1319,13 +1336,14 @@ void Utility::SetThreadName(const String& name, bool os)
#endif /* _WIN32 */
#ifdef HAVE_PTHREAD_SET_NAME_NP
pthread_set_name_np(pthread_self(), name.CStr());
pthread_set_name_np(pthread_self(), tname.CStr());
#elif defined(HAVE_PTHREAD_SETNAME_NP) /* HAVE_PTHREAD_SET_NAME_NP */
# ifdef __APPLE__
pthread_setname_np(name.CStr());
# else /* __APPLE__ */
String tname = name.SubStr(0, 15);
pthread_setname_np(pthread_self(), tname.CStr());
pthread_setname_np(tname.CStr());
# elif defined(__NetBSD__) /* __APPLE__ */
pthread_setname_np(pthread_self(), "%s", const_cast<char *>(tname.CStr()));
# else /* __NetBSD__ */
pthread_setname_np(pthread_self(), tname.CStr());
# endif /* __APPLE__ */
#endif /* HAVE_PTHREAD_SETNAME_NP */
}