From 4674678951a1315975d66016fb55c49100b7819f Mon Sep 17 00:00:00 2001 From: Xavi Hernandez Date: Thu, 24 Jan 2019 18:31:10 +0100 Subject: core: make gf_thread_create() easier to use This patch creates a specific function to set the thread name using a string format and a variable argument list, like printf(). This function is used to set the thread name from gf_thread_create(), which now accepts a variable argument list to create the full name. It's not necessary anymore to use a local array to build the name of the thread. This is done automatically. Change-Id: Idd8d01fd462c227359b96e98699f8c6d962dc17c Updates: bz#1193929 Signed-off-by: Xavi Hernandez --- libglusterfs/src/glusterfs/common-utils.h | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'libglusterfs/src/glusterfs/common-utils.h') diff --git a/libglusterfs/src/glusterfs/common-utils.h b/libglusterfs/src/glusterfs/common-utils.h index 89b38e02448..f03d2c1049a 100644 --- a/libglusterfs/src/glusterfs/common-utils.h +++ b/libglusterfs/src/glusterfs/common-utils.h @@ -147,9 +147,8 @@ trap(void); /* pthread related */ /* as per the man page, thread-name should be at max 16 bytes */ /* with prefix of 'glfs_' (5), we are left with 11 more bytes */ -#define GF_THREAD_NAMEMAX 11 +#define GF_THREAD_NAME_LIMIT 16 #define GF_THREAD_NAME_PREFIX "glfs_" -#define GF_THREAD_NAME_PREFIX_LEN 5 /* * we could have initialized these as +ve values and treated @@ -950,10 +949,24 @@ gf_set_timestamp(const char *src, const char *dest); int gf_thread_create(pthread_t *thread, const pthread_attr_t *attr, - void *(*start_routine)(void *), void *arg, const char *name); + void *(*start_routine)(void *), void *arg, const char *name, + ...) __attribute__((__format__(__printf__, 5, 6))); + +int +gf_thread_vcreate(pthread_t *thread, const pthread_attr_t *attr, + void *(*start_routine)(void *), void *arg, const char *name, + va_list args); int gf_thread_create_detached(pthread_t *thread, void *(*start_routine)(void *), - void *arg, const char *name); + void *arg, const char *name, ...) + __attribute__((__format__(__printf__, 4, 5))); + +void +gf_thread_set_name(pthread_t thread, const char *name, ...) + __attribute__((__format__(__printf__, 2, 3))); + +void +gf_thread_set_vname(pthread_t thread, const char *name, va_list args); gf_boolean_t gf_is_pid_running(int pid); gf_boolean_t -- cgit