diff --git a/src/dnsperf.c b/src/dnsperf.c index d8520ae..1fb6dca 100644 --- a/src/dnsperf.c +++ b/src/dnsperf.c @@ -1582,13 +1582,13 @@ threadinfo_init(threadinfo_t* tinfo, const config_t* config, } tinfo->current_sock = 0; - char name[16]; + char name[32]; PERF_THREAD(&tinfo->receiver, do_recv, tinfo); - snprintf(name, sizeof(name), "perf-recv-%04d", idx); - perf_thread_setname(tinfo->receiver, name); + snprintf(name, sizeof(name), "dnsperf-recv-%04d", idx); + perf_os_thread_setname(tinfo->receiver, name); PERF_THREAD(&tinfo->sender, do_send, tinfo); - snprintf(name, sizeof(name), "perf-send-%04d", idx); - perf_thread_setname(tinfo->sender, name); + snprintf(name, sizeof(name), "dnsperf-send-%04d", idx); + perf_os_thread_setname(tinfo->sender, name); } static void diff --git a/src/os.c b/src/os.c index a36cbed..e601343 100644 --- a/src/os.c +++ b/src/os.c @@ -32,6 +32,10 @@ #include #include +#if defined(HAVE_PTHREAD_NP_H) +#include +#endif /* if defined(HAVE_PTHREAD_NP_H) */ + void perf_os_blocksignal(int sig, bool block) { sigset_t sset; @@ -149,3 +153,23 @@ perf_os_waituntilanywritable(struct perf_net_socket** socks, unsigned int nfds, return (PERF_R_SUCCESS); } } + +void perf_os_thread_setname(pthread_t thread, const char* name) +{ +#if defined(HAVE_PTHREAD_SETNAME_NP) && !defined(__APPLE__) + /* + * macOS has pthread_setname_np but only works on the + * current thread so it's not used here + */ +#if defined(__NetBSD__) + (void)pthread_setname_np(thread, name, NULL); +#else /* if defined(__NetBSD__) */ + (void)pthread_setname_np(thread, name); +#endif /* if defined(__NetBSD__) */ +#elif defined(HAVE_PTHREAD_SET_NAME_NP) + (void)pthread_set_name_np(thread, name); +#else /* if defined(HAVE_PTHREAD_SETNAME_NP) && !defined(__APPLE__) */ + (void)(thread); + (void)(name); +#endif /* if defined(HAVE_PTHREAD_SETNAME_NP) && !defined(__APPLE__) */ +} diff --git a/src/os.h b/src/os.h index 0d9e8c5..8c2a20c 100644 --- a/src/os.h +++ b/src/os.h @@ -25,6 +25,7 @@ #include #include +#include void perf_os_blocksignal(int sig, bool block); @@ -41,4 +42,6 @@ perf_result_t perf_os_waituntilanywritable(struct perf_net_socket** socks, unsigned int nfds, int pipe_fd, int64_t timeout); +void perf_os_thread_setname(pthread_t thread, const char* name); + #endif diff --git a/src/util.h b/src/util.h index 04b7f17..ae821b0 100644 --- a/src/util.h +++ b/src/util.h @@ -23,12 +23,7 @@ #ifndef PERF_UTIL_H #define PERF_UTIL_H 1 -#include "config.h" #include -#if defined(HAVE_PTHREAD_NP_H) -#include -#endif /* if defined(HAVE_PTHREAD_NP_H) */ - #include #include #include @@ -162,24 +157,4 @@ static __inline__ uint64_t perf_get_time(void) #define PERF_SAFE_DIV(n, d) ((d) == 0 ? 0 : (n) / (d)) -static void -perf_thread_setname(pthread_t thread, const char* name) -{ -#if defined(HAVE_PTHREAD_SETNAME_NP) && !defined(__APPLE__) - /* - * macOS has pthread_setname_np but only works on the - * current thread so it's not used here - */ -#if defined(__NetBSD__) - (void)pthread_setname_np(thread, name, NULL); -#else /* if defined(__NetBSD__) */ - (void)pthread_setname_np(thread, name); -#endif /* if defined(__NetBSD__) */ -#elif defined(HAVE_PTHREAD_SET_NAME_NP) - (void)pthread_set_name_np(thread, name); -#else /* if defined(HAVE_PTHREAD_SETNAME_NP) && !defined(__APPLE__) */ - (void)(thread); - (void)(name); -#endif /* if defined(HAVE_PTHREAD_SETNAME_NP) && !defined(__APPLE__) */ -} #endif