From a60cb0b98317584d79af15b4a497ef60ea819d68 Mon Sep 17 00:00:00 2001 From: Wan-Teh Chang Date: Wed, 20 Jun 2012 15:46:33 -0700 Subject: [PATCH] Bug 758837: shorten a long thread name by eliding the middle part of the thread name with a '~'. Bug 763410: fix compilation error on MinGW. --- nsprpub/TAG-INFO | 2 +- nsprpub/config/prdepend.h | 1 + nsprpub/pr/src/md/windows/ntthread.c | 2 ++ nsprpub/pr/src/md/windows/w95thred.c | 2 ++ nsprpub/pr/src/pthreads/ptthread.c | 17 ++++++++++++----- nsprpub/pr/src/threads/combined/pruthr.c | 6 +++--- 6 files changed, 21 insertions(+), 9 deletions(-) diff --git a/nsprpub/TAG-INFO b/nsprpub/TAG-INFO index a5fbfe55505..86d38ca90a4 100644 --- a/nsprpub/TAG-INFO +++ b/nsprpub/TAG-INFO @@ -1 +1 @@ -NSPR_4_9_2_BETA1 +NSPR_4_9_2_BETA2 diff --git a/nsprpub/config/prdepend.h b/nsprpub/config/prdepend.h index e49e92677e3..6c66b37ca0f 100644 --- a/nsprpub/config/prdepend.h +++ b/nsprpub/config/prdepend.h @@ -10,3 +10,4 @@ */ #error "Do not include this header file." + diff --git a/nsprpub/pr/src/md/windows/ntthread.c b/nsprpub/pr/src/md/windows/ntthread.c index d695fe40e85..3814142d90e 100644 --- a/nsprpub/pr/src/md/windows/ntthread.c +++ b/nsprpub/pr/src/md/windows/ntthread.c @@ -291,6 +291,7 @@ typedef struct tagTHREADNAME_INFO void _PR_MD_SET_CURRENT_THREAD_NAME(const char *name) { +#ifdef _MSC_VER THREADNAME_INFO info; if (!IsDebuggerPresent()) @@ -308,6 +309,7 @@ _PR_MD_SET_CURRENT_THREAD_NAME(const char *name) (ULONG_PTR*)&info); } __except(EXCEPTION_CONTINUE_EXECUTION) { } +#endif } void diff --git a/nsprpub/pr/src/md/windows/w95thred.c b/nsprpub/pr/src/md/windows/w95thred.c index 21b4a6eac25..be92e2089f9 100644 --- a/nsprpub/pr/src/md/windows/w95thred.c +++ b/nsprpub/pr/src/md/windows/w95thred.c @@ -183,6 +183,7 @@ typedef struct tagTHREADNAME_INFO void _PR_MD_SET_CURRENT_THREAD_NAME(const char *name) { +#ifdef _MSC_VER THREADNAME_INFO info; if (!IsDebuggerPresent()) @@ -200,6 +201,7 @@ _PR_MD_SET_CURRENT_THREAD_NAME(const char *name) (ULONG_PTR*)&info); } __except(EXCEPTION_CONTINUE_EXECUTION) { } +#endif } void diff --git a/nsprpub/pr/src/pthreads/ptthread.c b/nsprpub/pr/src/pthreads/ptthread.c index 34c0bb12dca..9b98dd25c54 100644 --- a/nsprpub/pr/src/pthreads/ptthread.c +++ b/nsprpub/pr/src/pthreads/ptthread.c @@ -1631,11 +1631,11 @@ PR_IMPLEMENT(PRStatus) PR_SetCurrentThreadName(const char *name) return PR_FAILURE; PR_Free(thread->name); - nameLen = strlen(name) + 1; - thread->name = (char *)PR_Malloc(nameLen); + nameLen = strlen(name); + thread->name = (char *)PR_Malloc(nameLen + 1); if (!thread->name) return PR_FAILURE; - memcpy(thread->name, name, nameLen); + memcpy(thread->name, name, nameLen + 1); #if defined(OPENBSD) || defined(FREEBSD) result = pthread_set_name_np(thread->id, name); @@ -1657,9 +1657,16 @@ PR_IMPLEMENT(PRStatus) PR_SetCurrentThreadName(const char *name) return PR_SUCCESS; #define SETNAME_LENGTH_CONSTRAINT 15 +#define SETNAME_FRAGMENT1_LENGTH (SETNAME_LENGTH_CONSTRAINT >> 1) +#define SETNAME_FRAGMENT2_LENGTH \ + (SETNAME_LENGTH_CONSTRAINT - SETNAME_FRAGMENT1_LENGTH - 1) char name_dup[SETNAME_LENGTH_CONSTRAINT + 1]; - if (nameLen > SETNAME_LENGTH_CONSTRAINT + 1) { - memcpy(name_dup, name, SETNAME_LENGTH_CONSTRAINT); + if (nameLen > SETNAME_LENGTH_CONSTRAINT) { + memcpy(name_dup, name, SETNAME_FRAGMENT1_LENGTH); + name_dup[SETNAME_FRAGMENT1_LENGTH] = '~'; + memcpy(name_dup + SETNAME_FRAGMENT1_LENGTH + 1, + name + nameLen - SETNAME_FRAGMENT2_LENGTH, + SETNAME_FRAGMENT2_LENGTH); name_dup[SETNAME_LENGTH_CONSTRAINT] = '\0'; name = name_dup; } diff --git a/nsprpub/pr/src/threads/combined/pruthr.c b/nsprpub/pr/src/threads/combined/pruthr.c index fa5f5209854..7ecccf555d9 100644 --- a/nsprpub/pr/src/threads/combined/pruthr.c +++ b/nsprpub/pr/src/threads/combined/pruthr.c @@ -1597,11 +1597,11 @@ PR_IMPLEMENT(PRStatus) PR_SetCurrentThreadName(const char *name) return PR_FAILURE; PR_Free(thread->name); - nameLen = strlen(name) + 1; - thread->name = (char *)PR_Malloc(nameLen); + nameLen = strlen(name); + thread->name = (char *)PR_Malloc(nameLen + 1); if (!thread->name) return PR_FAILURE; - memcpy(thread->name, name, nameLen); + memcpy(thread->name, name, nameLen + 1); _PR_MD_SET_CURRENT_THREAD_NAME(thread->name); return PR_SUCCESS; }