Bug 1323100 - Use nsThreadPoolNaming::GetNextThreadName and NS_NewNamedThread in the DecodePool. r?froydnj draft
authorMarkus Stange <mstange@themasta.com>
Tue, 20 Dec 2016 14:20:48 +0100
changeset 456880 321deb0a3e81511e3e4c5a042ebbbb19c3b036f3
parent 456879 58e73a3fe700792b823c740503b093df38afe67d
child 456881 921eb514e051aa7df4d9a7f46cf8404c617010ba
push id40636
push userbmo:mstange@themasta.com
push dateFri, 06 Jan 2017 12:38:48 +0000
reviewersfroydnj
bugs1323100
milestone53.0a1
Bug 1323100 - Use nsThreadPoolNaming::GetNextThreadName and NS_NewNamedThread in the DecodePool. r?froydnj MozReview-Commit-ID: CAbaAe0bKe8
image/DecodePool.cpp
--- a/image/DecodePool.cpp
+++ b/image/DecodePool.cpp
@@ -55,24 +55,16 @@ public:
   MOZ_DECLARE_REFCOUNTED_TYPENAME(DecodePoolImpl)
   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(DecodePoolImpl)
 
   DecodePoolImpl()
     : mMonitor("DecodePoolImpl")
     , mShuttingDown(false)
   { }
 
-  /// Initialize the current thread for use by the decode pool.
-  void InitCurrentThread()
-  {
-    MOZ_ASSERT(!NS_IsMainThread());
-
-    mThreadNaming.SetThreadPoolName(NS_LITERAL_CSTRING("ImgDecoder"));
-  }
-
   /// Shut down the provided decode pool thread.
   static void ShutdownThread(nsIThread* aThisThread)
   {
     // Threads have to be shut down from another thread, so we'll ask the
     // main thread to do it for us.
     NS_DispatchToMainThread(NewRunnableMethod(aThisThread, &nsIThread::Shutdown));
   }
 
@@ -130,16 +122,22 @@ public:
         return work;
       }
 
       // Nothing to do; block until some work is available.
       mMonitor.Wait();
     } while (true);
   }
 
+  nsresult CreateThread(nsIThread** aThread, nsIRunnable* aInitialEvent)
+  {
+    return NS_NewNamedThread(mThreadNaming.GetNextThreadName("ImgDecoder"),
+                             aThread, aInitialEvent);
+  }
+
 private:
   ~DecodePoolImpl() { }
 
   Work PopWorkFromQueue(nsTArray<RefPtr<IDecodingTask>>& aQueue)
   {
     Work work;
     work.mType = Work::Type::TASK;
     work.mTask = aQueue.LastElement().forget();
@@ -161,32 +159,21 @@ class DecodePoolWorker : public Runnable
 {
 public:
   explicit DecodePoolWorker(DecodePoolImpl* aImpl)
     : mImpl(aImpl)
   { }
 
   NS_IMETHOD Run() override
   {
-#ifdef MOZ_ENABLE_PROFILER_SPS
-    char stackBaseGuess; // Need to be the first variable of main loop function.
-#endif // MOZ_ENABLE_PROFILER_SPS
-
     MOZ_ASSERT(!NS_IsMainThread());
 
-    mImpl->InitCurrentThread();
-
     nsCOMPtr<nsIThread> thisThread;
     nsThreadManager::get().GetCurrentThread(getter_AddRefs(thisThread));
 
-#ifdef MOZ_ENABLE_PROFILER_SPS
-    // InitCurrentThread() has assigned the thread name.
-    profiler_register_thread(PR_GetThreadName(PR_GetCurrentThread()), &stackBaseGuess);
-#endif // MOZ_ENABLE_PROFILER_SPS
-
     do {
       Work work = mImpl->PopWork();
       switch (work.mType) {
         case Work::Type::TASK:
           work.mTask->Run();
           break;
 
         case Work::Type::SHUTDOWN:
@@ -267,17 +254,17 @@ DecodePool::DecodePool()
   if (limit > 4 && XRE_IsParentProcess() && BrowserTabsRemoteAutostart()) {
     limit = 4;
   }
 
   // Initialize the thread pool.
   for (uint32_t i = 0 ; i < limit ; ++i) {
     nsCOMPtr<nsIRunnable> worker = new DecodePoolWorker(mImpl);
     nsCOMPtr<nsIThread> thread;
-    nsresult rv = NS_NewThread(getter_AddRefs(thread), worker);
+    nsresult rv = mImpl->CreateThread(getter_AddRefs(thread), worker);
     MOZ_RELEASE_ASSERT(NS_SUCCEEDED(rv) && thread,
                        "Should successfully create image decoding threads");
     mThreads.AppendElement(Move(thread));
   }
 
   // Initialize the I/O thread.
   nsresult rv = NS_NewNamedThread("ImageIO", getter_AddRefs(mIOThread));
   MOZ_RELEASE_ASSERT(NS_SUCCEEDED(rv) && mIOThread,