Bug 1323100 - Use NS_NewNamedThread for IndexedDB threads. r?froydnj draft
authorMarkus Stange <mstange@themasta.com>
Wed, 21 Dec 2016 11:26:48 +0100
changeset 456869 7a0065d2d5f9d1bb0a93540895741f218dbc4c07
parent 456868 b12772888df54e977876ed050d2ff7f12669a794
child 456870 77cbebe3a799f0c107622268fe12ade97460c4e9
push id40636
push userbmo:mstange@themasta.com
push dateFri, 06 Jan 2017 12:38:48 +0000
reviewersfroydnj
bugs1323100
milestone53.0a1
Bug 1323100 - Use NS_NewNamedThread for IndexedDB threads. r?froydnj MozReview-Commit-ID: Do4l5QL2qSG
dom/indexedDB/ActorsParent.cpp
--- a/dom/indexedDB/ActorsParent.cpp
+++ b/dom/indexedDB/ActorsParent.cpp
@@ -5715,16 +5715,21 @@ public:
   NS_DECL_ISUPPORTS_INHERITED
 
   uint32_t
   SerialNumber() const
   {
     return mSerialNumber;
   }
 
+  nsCString GetThreadName() const
+  {
+    return nsPrintfCString("IndexedDB #%lu", mSerialNumber);
+  }
+
 private:
   ~ThreadRunnable() override;
 
   NS_DECL_NSIRUNNABLE
 };
 
 class ConnectionPool::TransactionInfo final
 {
@@ -12566,17 +12571,20 @@ ConnectionPool::ScheduleTransaction(Tran
     if (mIdleThreads.IsEmpty()) {
       bool created = false;
 
       if (mTotalThreadCount < kMaxConnectionThreadCount) {
         // This will set the thread up with the profiler.
         RefPtr<ThreadRunnable> runnable = new ThreadRunnable();
 
         nsCOMPtr<nsIThread> newThread;
-        if (NS_SUCCEEDED(NS_NewThread(getter_AddRefs(newThread), runnable))) {
+        nsresult rv =
+          NS_NewNamedThread(runnable->GetThreadName(),
+                            getter_AddRefs(newThread), runnable);
+        if (NS_SUCCEEDED(rv)) {
           MOZ_ASSERT(newThread);
 
           IDB_DEBUG_LOG(("ConnectionPool created thread %lu",
                          runnable->SerialNumber()));
 
           dbInfo->mThreadInfo.mThread.swap(newThread);
           dbInfo->mThreadInfo.mRunnable.swap(runnable);
 
@@ -13279,43 +13287,27 @@ ThreadRunnable::~ThreadRunnable()
 }
 
 NS_IMPL_ISUPPORTS_INHERITED0(ConnectionPool::ThreadRunnable, Runnable)
 
 nsresult
 ConnectionPool::
 ThreadRunnable::Run()
 {
-#ifdef MOZ_ENABLE_PROFILER_SPS
-  char stackTopGuess;
-#endif // MOZ_ENABLE_PROFILER_SPS
-
   MOZ_ASSERT(!IsOnBackgroundThread());
   MOZ_ASSERT(mContinueRunning);
 
   if (!mFirstRun) {
     mContinueRunning = false;
     return NS_OK;
   }
 
   mFirstRun = false;
 
   {
-    // Scope for the thread name. Both PR_SetCurrentThreadName() and
-    // profiler_register_thread() copy the string so we don't need to keep it.
-    const nsPrintfCString threadName("IndexedDB #%lu", mSerialNumber);
-
-    PR_SetCurrentThreadName(threadName.get());
-
-#ifdef MOZ_ENABLE_PROFILER_SPS
-    profiler_register_thread(threadName.get(), &stackTopGuess);
-#endif // MOZ_ENABLE_PROFILER_SPS
-  }
-
-  {
     // Scope for the profiler label.
     PROFILER_LABEL("IndexedDB",
                    "ConnectionPool::ThreadRunnable::Run",
                    js::ProfileEntry::Category::STORAGE);
 
     nsIThread* currentThread = NS_GetCurrentThread();
     MOZ_ASSERT(currentThread);
 
@@ -13346,20 +13338,16 @@ ThreadRunnable::Run()
         MOZ_ALWAYS_TRUE(
           PR_Sleep(PR_MillisecondsToInterval(kDEBUGTransactionThreadSleepMS)) ==
             PR_SUCCESS);
       }
 #endif // DEBUG
     }
   }
 
-#ifdef MOZ_ENABLE_PROFILER_SPS
-  profiler_unregister_thread();
-#endif // MOZ_ENABLE_PROFILER_SPS
-
   return NS_OK;
 }
 
 ConnectionPool::
 ThreadInfo::ThreadInfo()
 {
   AssertIsOnBackgroundThread();