]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
VThread: factor out common thread-name assignment
authorOliver Kurth <okurth@vmware.com>
Fri, 15 Sep 2017 18:23:52 +0000 (11:23 -0700)
committerOliver Kurth <okurth@vmware.com>
Fri, 15 Sep 2017 18:23:52 +0000 (11:23 -0700)
open-vm-tools/lib/include/vthreadBase.h
open-vm-tools/lib/misc/vthreadBase.c

index f786fe0bef26e922ffa5647c6743869733c4d7c8..c9a44f8e76ce3dabd753898097e266d7e3ef4693 100644 (file)
@@ -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);
index fca5860e84e4b72c7b43c5690df764b8ff3f955c..cbe163177be4c0475fb86c8c92beae9a1bb4dcdc 100644 (file)
@@ -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);
+}
+
+
 /*
  *-----------------------------------------------------------------------------
  *