That function exists on Mac, but it only takes a single argument, the thread's new name. That's OK for our purposes, since we were calling it on pthread_self anyhow.
Signed-off-by: Chip Davis cdavis@codeweavers.com ---
Notes: Try 2: Pull the pthread_setname_np(3) call into a header.
Try 3: Detect which variant of pthread_setname_np(3) we have at configure time.
configure.ac | 28 ++++++++++++++++++++++++++++ libs/vkd3d/command.c | 4 +--- libs/vkd3d/vkd3d_private.h | 11 +++++++++++ 3 files changed, 40 insertions(+), 3 deletions(-)
diff --git a/configure.ac b/configure.ac index 2773a15..973105b 100644 --- a/configure.ac +++ b/configure.ac @@ -94,6 +94,34 @@ VKD3D_CHECK_FUNC([HAVE_SYNC_ADD_AND_FETCH], [__sync_add_and_fetch], [__sync_add_ VKD3D_CHECK_FUNC([HAVE_SYNC_SUB_AND_FETCH], [__sync_sub_and_fetch], [__sync_sub_and_fetch((int *)0, 0)])
VKD3D_CHECK_LIB_FUNCS([pthread_setname_np], [$PTHREAD_LIBS]) +AS_IF([test "x$ac_cv_func_pthread_setname_np" = xyes], + [AC_MSG_CHECKING([which variant of pthread_setname_np is present]) + AC_CACHE_VAL([vkd3d_cv_pthread_setname_np_variant], + [vkd3d_cv_pthread_setname_np_variant=unknown + AC_COMPILE_IFELSE([AC_LANG_PROGRAM( + [#ifdef HAVE_PTHREAD_H + #include <pthread.h> + #endif + ], + [pthread_setname_np(pthread_self(), "conftest");])], + [vkd3d_cv_pthread_setname_np_variant=twoarg], + [AC_COMPILE_IFELSE([AC_LANG_PROGRAM( + [#ifdef HAVE_PTHREAD_H + #include <pthread.h> + #endif + ], + [pthread_setname_np("conftest");])], + [vkd3d_cv_pthread_setname_np_variant=onearg])])]) + AS_CASE(["$vkd3d_cv_pthread_setname_np_variant"], + [onearg], + [AC_DEFINE([HAVE_PTHREAD_SETNAME_NP_ONEARG], [1], + [Define to 1 if you have the version of pthread_setname_np(3) that only accepts a name.]) + AC_MSG_RESULT([name only])], + [twoarg], + [AC_DEFINE([HAVE_PTHREAD_SETNAME_NP_TWOARG], [1], + [Define to 1 if you have the version of pthread_setname_np(3) that accepts a pthread handle and name.]) + AC_MSG_RESULT([pthread handle and name])], + [AC_MSG_RESULT([unknown])])])
AM_CONDITIONAL([HAVE_WIDL], [test "x$WIDL" != "xno"]) AM_CONDITIONAL([HAVE_CROSSTARGET32], [test "x$CROSSTARGET32" != "xno"]) diff --git a/libs/vkd3d/command.c b/libs/vkd3d/command.c index 4db9967..042d2f1 100644 --- a/libs/vkd3d/command.c +++ b/libs/vkd3d/command.c @@ -199,9 +199,7 @@ static void *vkd3d_fence_worker_main(void *arg) struct vkd3d_fence_worker *worker = arg; int rc;
-#ifdef HAVE_PTHREAD_SETNAME_NP - pthread_setname_np(pthread_self(), "vkd3d_worker"); -#endif + vkd3d_set_thread_name("vkd3d_worker");
for (;;) { diff --git a/libs/vkd3d/vkd3d_private.h b/libs/vkd3d/vkd3d_private.h index 8efb930..ca9fbaf 100644 --- a/libs/vkd3d/vkd3d_private.h +++ b/libs/vkd3d/vkd3d_private.h @@ -86,6 +86,17 @@ struct vkd3d_vulkan_info VkPhysicalDeviceSparseProperties sparse_properties; };
+static inline void vkd3d_set_thread_name(const char *name) +{ +#ifdef HAVE_PTHREAD_SETNAME_NP +#ifdef HAVE_PTHREAD_SETNAME_NP_ONEARG + pthread_setname_np(name); +#elif defined(HAVE_PTHREAD_SETNAME_NP_TWOARG) + pthread_setname_np(pthread_self(), name); +#endif +#endif +} + struct vkd3d_instance { VkInstance vk_instance;