From: Oliver Kurth Date: Fri, 15 Sep 2017 18:23:52 +0000 (-0700) Subject: VThread: factor out common thread-name assignment X-Git-Tag: stable-10.2.0~81 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=63e4a016d5bba58121cbbebb8f7711a0bf70436c;p=thirdparty%2Fopen-vm-tools.git VThread: factor out common thread-name assignment --- diff --git a/open-vm-tools/lib/include/vthreadBase.h b/open-vm-tools/lib/include/vthreadBase.h index f786fe0be..c9a44f8e7 100644 --- a/open-vm-tools/lib/include/vthreadBase.h +++ b/open-vm-tools/lib/include/vthreadBase.h @@ -132,6 +132,7 @@ VThread_CurName(void) const char *VThreadBase_CurName(void); VThreadID VThreadBase_CurID(void); void VThreadBase_SetName(const char *name); +void VThreadBase_SetNamePrefix(const char *prefix); /* For implementing a thread library */ void VThreadBase_ForgetSelf(void); diff --git a/open-vm-tools/lib/misc/vthreadBase.c b/open-vm-tools/lib/misc/vthreadBase.c index fca5860e8..cbe163177 100644 --- a/open-vm-tools/lib/misc/vthreadBase.c +++ b/open-vm-tools/lib/misc/vthreadBase.c @@ -464,7 +464,8 @@ VThreadBase_CurName(void) * None. * * Side effects: - * If current thread does not have a TLS block, one is allocated. + * If TLS is not supported, allocates thread-local memory which leaks + * on thread exit. (If this leak is a problem, implement TLS). * *----------------------------------------------------------------------------- */ @@ -508,6 +509,37 @@ VThreadBase_SetName(const char *name) // IN: new name } +/* + *----------------------------------------------------------------------------- + * + * VThreadBase_SetNamePrefix -- + * + * Override the default thread name with a new name based on + * the supplied prefix. Format is "{prefix}-{id}" + * + * Results: + * None. + * + * Side effects: + * None. + * + *----------------------------------------------------------------------------- + */ + +void +VThreadBase_SetNamePrefix(const char *prefix) // IN: name prefix +{ + char buf[VTHREADBASE_MAX_NAME]; + + ASSERT(prefix != NULL); + + snprintf(buf, sizeof buf, "%s-%" FMT64 "u", + prefix, VThreadBase_GetKernelID()); + buf[sizeof buf - 1] = '\0'; // snprintf does not ensure NUL-term + VThreadBase_SetName(buf); +} + + /* *----------------------------------------------------------------------------- *