Bug 1476729 - Wrap object in RefPtr. r=froydnj
authorJean-Yves Avenard <jyavenard@mozilla.com>
Thu, 19 Jul 2018 19:23:16 +0000
changeset 427374 d7e4562538d3a335089811b6ad6e278d64df5222
parent 427373 7f73954c5633e0b9ddf209cd4f92e710f8bed63c
child 427375 2bd269c5952cfda90ac7a444d263af6b9f36445d
push id34303
push usertoros@mozilla.com
push dateFri, 20 Jul 2018 09:55:38 +0000
treeherdermozilla-central@47f713574cb2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1476729
milestone63.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1476729 - Wrap object in RefPtr. r=froydnj Differential Revision: https://phabricator.services.mozilla.com/D2243
xpcom/threads/SharedThreadPool.cpp
--- a/xpcom/threads/SharedThreadPool.cpp
+++ b/xpcom/threads/SharedThreadPool.cpp
@@ -97,17 +97,17 @@ SharedThreadPool::SpinUntilEmpty()
   });
 }
 
 already_AddRefed<SharedThreadPool>
 SharedThreadPool::Get(const nsCString& aName, uint32_t aThreadLimit)
 {
   MOZ_ASSERT(sMonitor && sPools);
   ReentrantMonitorAutoEnter mon(*sMonitor);
-  SharedThreadPool* pool = nullptr;
+  RefPtr<SharedThreadPool> pool;
   nsresult rv;
 
   if (auto entry = sPools->LookupForAdd(aName)) {
     pool = entry.Data();
     if (NS_FAILED(pool->EnsureThreadLimitIsAtLeast(aThreadLimit))) {
       NS_WARNING("Failed to set limits on thread pool");
     }
   } else {
@@ -130,22 +130,20 @@ SharedThreadPool::Get(const nsCString& a
     }
 
     rv = pool->SetIdleThreadLimit(aThreadLimit);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       sPools->Remove(aName); // XXX entry.Remove()
       return nullptr;
     }
 
-    entry.OrInsert([pool] () { return pool; });
+    entry.OrInsert([pool] () { return pool.get(); });
   }
 
-  MOZ_ASSERT(pool);
-  RefPtr<SharedThreadPool> instance(pool);
-  return instance.forget();
+  return pool.forget();
 }
 
 NS_IMETHODIMP_(MozExternalRefCountType) SharedThreadPool::AddRef(void)
 {
   MOZ_ASSERT(sMonitor);
   ReentrantMonitorAutoEnter mon(*sMonitor);
   MOZ_ASSERT(int32_t(mRefCnt) >= 0, "illegal refcnt");
   nsrefcnt count = ++mRefCnt;