From: Oliver Kurth Date: Fri, 15 Sep 2017 18:23:25 +0000 (-0700) Subject: Move VThread_CurName() entirely to thread-local storage X-Git-Tag: stable-10.2.0~342 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ecc7259e47548e13189a79544fc66324d87e00e2;p=thirdparty%2Fopen-vm-tools.git Move VThread_CurName() entirely to thread-local storage A previous change switched VThreadBase to store thread names in thread-local storage on most platforms (all except mobile). This change is the follow-up: removing the old storage location for thread names. Briefly, this change removes the "name" field from VThreadBaseData and handles all the fallout. That's mostly straightforward, though lib/thread ended up storing a thread name in the "reserved" thread structures - this is mostly so the name passed to VThread_ReserveID would be preserved until VThread_CreateThread is called. After this, vthreadBase.c complexity only remains for VThreadIDs, which is the next step of this effort. --- diff --git a/open-vm-tools/lib/include/vthreadBase.h b/open-vm-tools/lib/include/vthreadBase.h index d5d6c1781..cc58dac9e 100644 --- a/open-vm-tools/lib/include/vthreadBase.h +++ b/open-vm-tools/lib/include/vthreadBase.h @@ -106,7 +106,6 @@ VThread_CurName(void) typedef struct { VThreadID id; - char name[VTHREADBASE_MAX_NAME]; } VThreadBaseData; /* Common VThreadBase functions */ diff --git a/open-vm-tools/lib/misc/vthreadBase.c b/open-vm-tools/lib/misc/vthreadBase.c index b9f0edbac..17e25db8d 100644 --- a/open-vm-tools/lib/misc/vthreadBase.c +++ b/open-vm-tools/lib/misc/vthreadBase.c @@ -895,8 +895,8 @@ VThreadBase_InitWithTLS(VThreadBaseData *base) // IN: caller-managed storage * means the cooking function is broken - it should block signals - or * an ASSERT triggered while setting up the VThreadID. */ - Log("VThreadBase reinitialization, old: %d %s, new: %d %s.\n", - realBase->id, realBase->name, base->id, base->name); + Log("VThreadBase reinitialization, old: %d, new: %d.\n", + realBase->id, base->id); } return firstTime; @@ -928,7 +928,7 @@ static void VThreadBaseForgetNameRaw(void) { #if defined NEW_HAVE_TLS - strncpy(vthreadName, "", sizeof vthreadName); + memset(vthreadName, '\0', sizeof vthreadName); #else char *buf; @@ -947,7 +947,6 @@ VThreadBaseSafeDeleteTLS(void *tlsData) VThreadBaseData *data = tlsData; if (data != NULL) { - VThreadBaseForgetNameRaw(); // New-style TLS, will replace old-style soon if (vthreadBaseGlobals.freeIDFunc != NULL) { Bool success; VThreadBaseData tmpData = *data; @@ -962,7 +961,8 @@ VThreadBaseSafeDeleteTLS(void *tlsData) VERIFY(success); if (vmx86_debug) { - Log("Forgetting VThreadID %d (\"%s\").\n", data->id, data->name); + Log("Forgetting VThreadID %d (\"%s\").\n", + data->id, VThread_CurName()); } (*vthreadBaseGlobals.freeIDFunc)(data); @@ -970,6 +970,7 @@ VThreadBaseSafeDeleteTLS(void *tlsData) VThreadBaseSetID(VTHREAD_INVALID_ID); VERIFY(success); } + VThreadBaseForgetNameRaw(); Atomic_Dec(&vthreadBaseGlobals.numThreads); } } @@ -1032,7 +1033,7 @@ VThreadBaseSetNameRaw(const char *name) // IN: new name char *buf; ASSERT(vthreadNameKey != 0); - ASSERT(!VThreadBase_IsInSignal()); + ASSERT(!VThreadBase_IsInSignal()); // Cannot alloc in signal handler /* * The below code is racy (signal between get/set), but the @@ -1054,23 +1055,16 @@ VThreadBaseSetNameRaw(const char *name) // IN: new name void VThreadBase_SetName(const char *name) // IN: new name { - uint32 len = strlen(name); - VThreadBaseData *base = VThreadBaseGetAndInitBase(); + (void) VThreadBaseGetAndInitBase(); // Side effect of getting a VThreadID ASSERT(name); - if (len >= sizeof base->name) { - if (vmx86_debug) { - Warning("%s: thread name (%s) exceeds maximum length (%u)\n", - __FUNCTION__, name, (uint32) sizeof base->name -1); - } - - len = sizeof base->name - 1; + if (vmx86_debug && strlen(name) >= VTHREADBASE_MAX_NAME) { + Warning("%s: thread name (%s) exceeds maximum length (%u)\n", + __FUNCTION__, name, (uint32)VTHREADBASE_MAX_NAME - 1); } - memcpy(base->name, name, len); - base->name[len] = '\0'; - VThreadBaseSetNameRaw(name); // New-style TLS, will replace old-style soon + VThreadBaseSetNameRaw(name); } @@ -1193,6 +1187,7 @@ static void VThreadBaseSimpleNoID(void) { VThreadID newID; + char newName[VTHREADBASE_MAX_NAME]; Bool reused = FALSE; Bool result; void *newNative = VThreadBaseGetNative(); @@ -1251,10 +1246,10 @@ VThreadBaseSimpleNoID(void) /* ID picked. Now do the important stuff. */ base = Util_SafeCalloc(1, sizeof *base); base->id = newID; - Str_Sprintf(base->name, sizeof base->name, "vthread-%u", newID); + Str_Sprintf(newName, sizeof newName, "vthread-%u", newID); result = VThreadBase_InitWithTLS(base); - VThreadBase_SetName(base->name); // New-style TLS + VThreadBase_SetName(newName); ASSERT(result); if (vmx86_debug && reused) {