diff --git a/configure.ac b/configure.ac index a6104498..d437e1b7 100644 --- a/configure.ac +++ b/configure.ac @@ -94,7 +94,7 @@ VKD3D_CHECK_FUNC([HAVE_BUILTIN_POPCOUNT], [__builtin_popcount], [__builtin_popco VKD3D_CHECK_FUNC([HAVE_SYNC_ADD_AND_FETCH], [__sync_add_and_fetch], [__sync_add_and_fetch((int *)0, 0)]) 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]) +VKD3D_CHECK_PTHREAD_SETNAME_NP AM_CONDITIONAL([BUILD_DEMOS], [test "x$enable_demos" = "xyes"]) AM_CONDITIONAL([HAVE_WIDL], [test "x$WIDL" != "xno"]) diff --git a/libs/vkd3d/command.c b/libs/vkd3d/command.c index ce5f60fb..9aba589e 100644 --- a/libs/vkd3d/command.c +++ b/libs/vkd3d/command.c @@ -200,9 +200,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 f9a2f5a1..278f4f61 100644 --- a/libs/vkd3d/vkd3d_private.h +++ b/libs/vkd3d/vkd3d_private.h @@ -826,4 +826,13 @@ HRESULT vkd3d_load_vk_device_procs(struct vkd3d_vk_device_procs *procs, extern const char vkd3d_build[]; +static inline void vkd3d_set_thread_name(const char *name) +{ +#if defined(HAVE_PTHREAD_SETNAME_NP_2) + pthread_setname_np(pthread_self(), name); +#elif defined(HAVE_PTHREAD_SETNAME_NP_1) + pthread_setname_np(name); +#endif +} + #endif /* __VKD3D_PRIVATE_H */ diff --git a/m4/check-functions.m4 b/m4/check-functions.m4 index 17082a17..4d018d69 100644 --- a/m4/check-functions.m4 +++ b/m4/check-functions.m4 @@ -14,3 +14,42 @@ AC_DEFUN([VKD3D_CHECK_LIB_FUNCS], LIBS="$LIBS $2" AC_CHECK_FUNCS([$1], [$3], [$4]) LIBS="$vkd3d_libs_saved"]) + +dnl VKD3D_CHECK_WHICH_PTHREAD_SETNAME_NP +AC_DEFUN([VKD3D_CHECK_WHICH_PTHREAD_SETNAME_NP], + [AC_MSG_CHECKING([how many arguments pthread_set_np() takes]) + AC_CACHE_VAL([vkd3d_cv_which_pthread_set_np], [ + +vkd3d_cv_which_pthread_set_np=unknown + +AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include ], + [pthread_setname_np(pthread_self(), "conftest")])], + [vkd3d_cv_which_pthread_set_np=two]) + +AS_IF([test "$vkd3d_cv_which_pthread_set_np" = "unknown"], + [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include ], + [pthread_setname_np("conftest")])], + [vkd3d_cv_which_pthread_set_np=one])]) + +]) dnl AC_CACHE_VAL + +AS_CASE(["$vkd3d_cv_which_pthread_set_np"], + [one], + [AC_DEFINE([HAVE_PTHREAD_SETNAME_NP_1], [1], + [Define to 1 if you have the one-argument variant of pthread_setname_np().]) + AC_MSG_RESULT([one])], + + [two], + [AC_DEFINE([HAVE_PTHREAD_SETNAME_NP_2], [1], + [Define to 1 if you have the two-argument variant of pthread_setname_np().]) + AC_MSG_RESULT([two])], + + [AC_MSG_RESULT([unknown])]) + +]) dnl AC_DEFUN + +dnl VKD3D_CHECK_PTHREAD_SETNAME_NP +AC_DEFUN([VKD3D_CHECK_PTHREAD_SETNAME_NP], + [VKD3D_CHECK_LIB_FUNCS([pthread_setname_np], [$PTHREAD_LIBS]) + AS_IF([test "x$ac_cv_func_pthread_setname_np" = "xyes"], + [VKD3D_CHECK_WHICH_PTHREAD_SETNAME_NP])])