From ef533e2e3fedbd647726416fa7f36ca543ee13ea Mon Sep 17 00:00:00 2001 From: Bernd Schubert Date: Thu, 24 Apr 2025 13:53:59 +0200 Subject: Add a fuse_set_thread_name() helper Avoid splattering the code with ifdef Signed-off-by: Bernd Schubert --- lib/fuse.c | 4 +--- lib/fuse_loop_mt.c | 4 +--- lib/util.c | 19 +++++++++++++++++++ lib/util.h | 3 ++- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/lib/fuse.c b/lib/fuse.c index bbf573a..9b9b983 100644 --- a/lib/fuse.c +++ b/lib/fuse.c @@ -4912,9 +4912,7 @@ static void *fuse_prune_nodes(void *fuse) struct fuse *f = fuse; int sleep_time; -#ifdef HAVE_PTHREAD_SETNAME_NP - pthread_setname_np(pthread_self(), "fuse_prune_nodes"); -#endif + fuse_set_thread_name(pthread_self(), "fuse_prune_nodes"); while(1) { sleep_time = fuse_clean_cache(f); diff --git a/lib/fuse_loop_mt.c b/lib/fuse_loop_mt.c index c13b476..46e2d6e 100644 --- a/lib/fuse_loop_mt.c +++ b/lib/fuse_loop_mt.c @@ -131,9 +131,7 @@ static void *fuse_do_work(void *data) struct fuse_mt *mt = w->mt; struct fuse_session *se = mt->se; -#ifdef HAVE_PTHREAD_SETNAME_NP - pthread_setname_np(pthread_self(), "fuse_worker"); -#endif + fuse_set_thread_name(pthread_self(), "fuse_worker"); while (!fuse_session_exited(se)) { int isforget = 0; diff --git a/lib/util.c b/lib/util.c index a529d38..00f1e1a 100644 --- a/lib/util.c +++ b/lib/util.c @@ -1,3 +1,12 @@ + +#include "fuse_config.h" + +#ifdef HAVE_PTHREAD_SETNAME_NP +#define _GNU_SOURCE +#include +#endif + +#include #include #include @@ -25,3 +34,13 @@ int libfuse_strtol(const char *str, long *res) *res = val; return 0; } + +void fuse_set_thread_name(unsigned long tid, const char *name) +{ +#ifdef HAVE_PTHREAD_SETNAME_NP + pthread_setname_np(tid, name); +#else + (void)tid; + (void)name; +#endif +} diff --git a/lib/util.h b/lib/util.h index ed03ad4..d1939cf 100644 --- a/lib/util.h +++ b/lib/util.h @@ -9,6 +9,7 @@ #define unlikely(x) __builtin_expect(!!(x), 0) int libfuse_strtol(const char *str, long *res); +void fuse_set_thread_name(unsigned long tid, const char *name); /** * Return the low bits of a number @@ -36,4 +37,4 @@ static inline uint64_t fuse_higher_32_bits(uint64_t nr) ((type *)(__mptr - offsetof(type, member))); \ }) -#endif +#endif /* FUSE_UTIL_H_ */ -- cgit v1.2.3