Bug 765158 - Remove naming of main thread, conflicts with process name on Linux, r=bsmedberg
authorHonza Bambas <honzab.moz@firemni.cz>
Tue, 10 Jul 2012 23:49:18 +0200
changeset 103669 7f6e22f10b99eb823d4f3fe039497aa1c9f87ad6
parent 103668 991404facac2f4884dca0257a767595471de1830
child 103670 30a4e0cf71304537eecdfeefc70310c9928e0430
push idunknown
push userunknown
push dateunknown
reviewersbsmedberg
bugs765158
milestone16.0a1
Bug 765158 - Remove naming of main thread, conflicts with process name on Linux, r=bsmedberg
xpcom/base/VisualEventTracer.cpp
xpcom/build/nsXPComInit.cpp
--- a/xpcom/base/VisualEventTracer.cpp
+++ b/xpcom/base/VisualEventTracer.cpp
@@ -5,17 +5,18 @@
 #include "mozilla/VisualEventTracer.h"
 #include "mozilla/Monitor.h"
 #include "mozilla/TimeStamp.h"
 #include "nscore.h"
 #include "prthread.h"
 #include "prprf.h"
 #include "prio.h"
 #include "prenv.h"
-#include "plstr.h"  
+#include "plstr.h"
+#include "nsThreadUtils.h"
 
 namespace mozilla { namespace eventtracer {
 
 #ifdef MOZ_VISUAL_EVENT_TRACER
 
 namespace {
 
 const PRUint32 kBatchSize = 0x1000;
@@ -49,25 +50,41 @@ public:
 
   PRUint32 mType;
   double mTime;
   void * mItem;
   char * mText;
   char * mText2;
 };
 
+char * DupCurrentThreadName()
+{
+  if (NS_IsMainThread())
+    return PL_strdup("Main Thread");
+
+  PRThread * currentThread = PR_GetCurrentThread();
+  const char * name = PR_GetThreadName(currentThread);
+  if (name)
+    return PL_strdup(name);
+
+  char buffer[128];
+  PR_snprintf(buffer, 127, "Nameless %p", currentThread);
+
+  return PL_strdup(buffer);
+}
+
 // An array of events, each thread keeps its own private instance
 class RecordBatch {
 public:
   RecordBatch()
     : mRecordsHead(new Record[kBatchSize])
     , mRecordsTail(mRecordsHead + kBatchSize)
     , mNextRecord(mRecordsHead)
     , mNextBatch(nsnull)
-    , mThreadNameCopy(PL_strdup(PR_GetThreadName(PR_GetCurrentThread())))
+    , mThreadNameCopy(DupCurrentThreadName())
   {
     MOZ_COUNT_CTOR(RecordBatch);
   }
 
   ~RecordBatch()
   {
     delete [] mRecordsHead;
     PL_strfree(mThreadNameCopy);
--- a/xpcom/build/nsXPComInit.cpp
+++ b/xpcom/build/nsXPComInit.cpp
@@ -310,18 +310,16 @@ NS_InitXPCOM(nsIServiceManager* *result,
 
 EXPORT_XPCOM_API(nsresult)
 NS_InitXPCOM2(nsIServiceManager* *result,
               nsIFile* binDirectory,
               nsIDirectoryServiceProvider* appFileLocationProvider)
 {
     NS_TIME_FUNCTION;
 
-    PR_SetCurrentThreadName("Main Thread");
-
     nsresult rv = NS_OK;
 
      // We are not shutting down
     gXPCOMShuttingDown = false;
 
     NS_TIME_FUNCTION_MARK("Next: AvailableMemoryTracker Init()");
 
     // Initialize the available memory tracker before other threads have had a