Bug 1323100 - Use nsThreadPoolNaming::GetNextThreadName and NS_NewNamedThread in the DecodePool. r?froydnj
MozReview-Commit-ID: CAbaAe0bKe8
--- 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,