summaryrefslogtreecommitdiffstats
path: root/libglusterfs/src/common-utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'libglusterfs/src/common-utils.c')
-rw-r--r--libglusterfs/src/common-utils.c27
1 files changed, 24 insertions, 3 deletions
diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c
index 1adb0bd5a81..ec1d5c4823c 100644
--- a/libglusterfs/src/common-utils.c
+++ b/libglusterfs/src/common-utils.c
@@ -3725,10 +3725,15 @@ gf_thread_cleanup_xint (pthread_t thread)
int
gf_thread_create (pthread_t *thread, const pthread_attr_t *attr,
- void *(*start_routine)(void *), void *arg)
+ void *(*start_routine)(void *), void *arg, const char *name)
{
sigset_t set, old;
int ret;
+ char thread_name[GF_THREAD_NAMEMAX+GF_THREAD_NAME_PREFIX_LEN] = {0,};
+ /* Max name on Linux is 16 and on NetBSD is 32
+ * All Gluster threads have a set prefix of gluster and hence the limit
+ * of 9 on GF_THREAD_NAMEMAX including the null character.
+ */
sigemptyset (&old);
sigfillset (&set);
@@ -3742,6 +3747,21 @@ gf_thread_create (pthread_t *thread, const pthread_attr_t *attr,
pthread_sigmask (SIG_BLOCK, &set, &old);
ret = pthread_create (thread, attr, start_routine, arg);
+ snprintf (thread_name, sizeof(thread_name), "%s%s",
+ GF_THREAD_NAME_PREFIX, name);
+
+ if (0 == ret && name) {
+ #ifdef GF_LINUX_HOST_OS
+ pthread_setname_np(*thread, thread_name);
+ #elif defined(__NetBSD__)
+ pthread_setname_np(*thread, thread_name, NULL);
+ #else
+ gf_msg (THIS->name, GF_LOG_WARNING, 0,
+ LG_MSG_PTHREAD_NAMING_FAILED,
+ "Thread names not implemented on this ",
+ "platform");
+ #endif
+ }
pthread_sigmask (SIG_SETMASK, &old, NULL);
@@ -3750,7 +3770,8 @@ gf_thread_create (pthread_t *thread, const pthread_attr_t *attr,
int
gf_thread_create_detached (pthread_t *thread,
- void *(*start_routine)(void *), void *arg)
+ void *(*start_routine)(void *), void *arg,
+ const char *name)
{
pthread_attr_t attr;
int ret = -1;
@@ -3765,7 +3786,7 @@ gf_thread_create_detached (pthread_t *thread,
pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
- ret = gf_thread_create (thread, &attr, start_routine, arg);
+ ret = gf_thread_create (thread, &attr, start_routine, arg, name);
if (ret) {
gf_msg (THIS->name, GF_LOG_ERROR, ret,
LG_MSG_PTHREAD_FAILED,