Bug 1323100 - Remove aThread argument from nsThreadPoolNaming::SetThreadPoolName, which is the last user of NS_SetThreadName. draft
authorMarkus Stange <mstange@themasta.com>
Mon, 12 Dec 2016 19:25:50 -0500
changeset 448852 6db4df4241daa73eb2a65f1d009944647dc0c71c
parent 448851 faffddfbf4e3be32fb8ef7af3c321cb4156d87d4
child 448853 a5b5461e3ee0b4e286f7d7881fffaf624864f4d3
push id38456
push userbmo:mstange@themasta.com
push dateTue, 13 Dec 2016 05:18:34 +0000
bugs1323100
milestone53.0a1
Bug 1323100 - Remove aThread argument from nsThreadPoolNaming::SetThreadPoolName, which is the last user of NS_SetThreadName. MozReview-Commit-ID: 3DRkwYxPLCf
storage/mozStorageConnection.cpp
xpcom/glue/nsThreadUtils.cpp
xpcom/glue/nsThreadUtils.h
--- a/storage/mozStorageConnection.cpp
+++ b/storage/mozStorageConnection.cpp
@@ -584,24 +584,23 @@ Connection::getAsyncExecutionTarget()
   MutexAutoLock lockedScope(sharedAsyncExecutionMutex);
 
   // If we are shutting down the asynchronous thread, don't hand out any more
   // references to the thread.
   if (mAsyncExecutionThreadShuttingDown)
     return nullptr;
 
   if (!mAsyncExecutionThread) {
-    nsresult rv = ::NS_NewThread(getter_AddRefs(mAsyncExecutionThread));
+    static nsThreadPoolNaming naming;
+    nsresult rv = naming.NewThreadWithThreadPoolName(NS_LITERAL_CSTRING("mozStorage"),
+                                                     getter_AddRefs(mAsyncExecutionThread));
     if (NS_FAILED(rv)) {
       NS_WARNING("Failed to create async thread.");
       return nullptr;
     }
-    static nsThreadPoolNaming naming;
-    naming.SetThreadPoolName(NS_LITERAL_CSTRING("mozStorage"),
-                             mAsyncExecutionThread);
   }
 
 #ifdef DEBUG
   mAsyncExecutionThreadIsAlive = true;
 #endif
 
   return mAsyncExecutionThread;
 }
--- a/xpcom/glue/nsThreadUtils.cpp
+++ b/xpcom/glue/nsThreadUtils.cpp
@@ -437,37 +437,47 @@ nsIThread*
 NS_GetCurrentThread()
 {
   return nsThreadManager::get().GetCurrentThread();
 }
 #endif
 
 // nsThreadPoolNaming
 void
-nsThreadPoolNaming::SetThreadPoolName(const nsACString& aPoolName,
-                                      nsIThread* aThread)
+nsThreadPoolNaming::SetThreadPoolName(const nsACString& aPoolName)
 {
   nsCString name(aPoolName);
   name.AppendLiteral(" #");
   name.AppendInt(++mCounter, 10); // The counter is declared as volatile
 
-  if (aThread) {
-    // Set on the target thread
-    NS_SetThreadName(aThread, name);
-  } else {
-    // Set on the current thread
+  // Set on the current thread
 #ifndef XPCOM_GLUE_AVOID_NSPR
-    PR_SetCurrentThreadName(name.BeginReading());
+  PR_SetCurrentThreadName(name.BeginReading());
 #endif
-  }
 
   char stackBaseGuess;
   profiler_register_thread(name.BeginReading(), &stackBaseGuess);
 }
 
+nsresult
+nsThreadPoolNaming::NewThreadWithThreadPoolName(const nsACString& aPoolName,
+                                                nsIThread** aThread)
+{
+  nsCString name(aPoolName);
+  name.AppendLiteral(" #");
+  name.AppendInt(++mCounter, 10); // The counter is declared as volatile
+
+  nsresult rv = NS_NewNamedThread(name, aThread);
+  if (NS_FAILED(rv)) {
+    mCounter--;
+  }
+
+  return rv;
+}
+
 // nsAutoLowPriorityIO
 nsAutoLowPriorityIO::nsAutoLowPriorityIO()
 {
 #if defined(XP_WIN)
   lowIOPrioritySet = IsVistaOrLater() &&
                      SetThreadPriority(GetCurrentThread(),
                                        THREAD_MODE_BACKGROUND_BEGIN);
 #elif defined(XP_MACOSX)
--- a/xpcom/glue/nsThreadUtils.h
+++ b/xpcom/glue/nsThreadUtils.h
@@ -1033,21 +1033,25 @@ private:
  */
 class nsThreadPoolNaming
 {
 public:
   nsThreadPoolNaming() : mCounter(0) {}
 
   /**
    * Creates and sets next thread name as "<aPoolName> #<n>"
-   * on the specified thread.  If no thread is specified (aThread
-   * is null) then the name is synchronously set on the current thread.
+   * on the current thread.
    */
-  void SetThreadPoolName(const nsACString& aPoolName,
-                         nsIThread* aThread = nullptr);
+  void SetThreadPoolName(const nsACString& aPoolName);
+
+  /**
+   * Creates a new thread and sets its thread name as "<aPoolName> #<n>".
+   */
+  nsresult NewThreadWithThreadPoolName(const nsACString& aPoolName,
+                                       nsIThread** aThread);
 
 private:
   mozilla::Atomic<uint32_t> mCounter;
 
   nsThreadPoolNaming(const nsThreadPoolNaming&) = delete;
   void operator=(const nsThreadPoolNaming&) = delete;
 };