From 0647877ae6763211f8f232be617c758644c0c33c Mon Sep 17 00:00:00 2001 From: Dridi Boukelmoune Date: Tue, 7 May 2024 09:52:39 +0200 Subject: [PATCH 1/2] Revert "Deautocrap: everybody has a pthread_setname_np(2) now." This reverts commit 41cdd270f72a6972e050c38a0fabb05793044c29. Even though everybody has a pthread_setname_np(3), they are different and not portable by definition. The safeguards should be preserved since THR_SetName() will at least allow a panic to get the thread name. --- bin/varnishd/cache/cache_main.c | 4 ++++ configure.ac | 2 ++ 2 files changed, 6 insertions(+) diff --git a/bin/varnishd/cache/cache_main.c b/bin/varnishd/cache/cache_main.c index d29d3d3aec..13d2098953 100644 --- a/bin/varnishd/cache/cache_main.c +++ b/bin/varnishd/cache/cache_main.c @@ -134,6 +134,9 @@ THR_SetName(const char *name) { PTOK(pthread_setspecific(name_key, name)); +#if defined(HAVE_PTHREAD_SET_NAME_NP) + pthread_set_name_np(pthread_self(), name); +#elif defined(HAVE_PTHREAD_SETNAME_NP) #if defined(__APPLE__) (void)pthread_setname_np(name); #elif defined(__NetBSD__) @@ -141,6 +144,7 @@ THR_SetName(const char *name) #else (void)pthread_setname_np(pthread_self(), name); #endif +#endif } const char * diff --git a/configure.ac b/configure.ac index e521893297..6c559799d4 100644 --- a/configure.ac +++ b/configure.ac @@ -229,6 +229,8 @@ AC_CHECK_FUNCS([fnmatch], [], [AC_MSG_ERROR([fnmatch(3) is required])]) save_LIBS="${LIBS}" LIBS="${PTHREAD_LIBS}" +AC_CHECK_FUNCS([pthread_set_name_np]) +AC_CHECK_FUNCS([pthread_setname_np]) AC_CHECK_FUNCS([pthread_mutex_isowned_np]) AC_CHECK_FUNCS([pthread_getattr_np]) LIBS="${save_LIBS}" From abf174dd55633ae34bc28c044883a868116478fc Mon Sep 17 00:00:00 2001 From: Dridi Boukelmoune Date: Tue, 7 May 2024 09:58:06 +0200 Subject: [PATCH 2/2] build: Drop support for pthread_set_name_np() We can rely on pthread_setname_np() for all the platforms we care about. The nested preprocessor conditions for pthread_setname_np are indented to improve readability. Better diff with the --ignore-all-space option. --- bin/varnishd/cache/cache_main.c | 12 +++++------- configure.ac | 1 - 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/bin/varnishd/cache/cache_main.c b/bin/varnishd/cache/cache_main.c index 13d2098953..8dcab3b751 100644 --- a/bin/varnishd/cache/cache_main.c +++ b/bin/varnishd/cache/cache_main.c @@ -134,16 +134,14 @@ THR_SetName(const char *name) { PTOK(pthread_setspecific(name_key, name)); -#if defined(HAVE_PTHREAD_SET_NAME_NP) - pthread_set_name_np(pthread_self(), name); -#elif defined(HAVE_PTHREAD_SETNAME_NP) -#if defined(__APPLE__) +#if defined(HAVE_PTHREAD_SETNAME_NP) +# if defined(__APPLE__) (void)pthread_setname_np(name); -#elif defined(__NetBSD__) +# elif defined(__NetBSD__) (void)pthread_setname_np(pthread_self(), "%s", (char *)(uintptr_t)name); -#else +# else (void)pthread_setname_np(pthread_self(), name); -#endif +# endif #endif } diff --git a/configure.ac b/configure.ac index 6c559799d4..00ffc9609e 100644 --- a/configure.ac +++ b/configure.ac @@ -229,7 +229,6 @@ AC_CHECK_FUNCS([fnmatch], [], [AC_MSG_ERROR([fnmatch(3) is required])]) save_LIBS="${LIBS}" LIBS="${PTHREAD_LIBS}" -AC_CHECK_FUNCS([pthread_set_name_np]) AC_CHECK_FUNCS([pthread_setname_np]) AC_CHECK_FUNCS([pthread_mutex_isowned_np]) AC_CHECK_FUNCS([pthread_getattr_np])