Bug 1389561 - Part 5: Prevent allocation of parent actors if quota manager is shutting down; r=luke
authorJan Varga <jan.varga@gmail.com>
Thu, 02 Nov 2017 14:54:29 +0800
changeset 389810 82f27b9d3b33c10b3d25a1d5f747763fc1696ba1
parent 389809 9ba5ec4843e8da516c3a4f4bbf60cc11d8e80a37
child 389811 9d76daebda9950f970730fa3f733ffeb66723463
push id32797
push userapavel@mozilla.com
push dateThu, 02 Nov 2017 13:30:39 +0000
treeherdermozilla-central@40a14ca1cf04 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersluke
bugs1389561
milestone58.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 1389561 - Part 5: Prevent allocation of parent actors if quota manager is shutting down; r=luke
dom/asmjscache/AsmJSCache.cpp
--- a/dom/asmjscache/AsmJSCache.cpp
+++ b/dom/asmjscache/AsmJSCache.cpp
@@ -242,17 +242,51 @@ EvictEntries(nsIFile* aDirectory, const 
 
 /*******************************************************************************
  * Client
  ******************************************************************************/
 
 class Client
   : public quota::Client
 {
+  static Client* sInstance;
+
+  bool mShutdownRequested;
+
 public:
+  Client();
+
+  static bool
+  IsShuttingDownOnBackgroundThread()
+  {
+    AssertIsOnBackgroundThread();
+
+    if (sInstance) {
+      return sInstance->IsShuttingDown();
+    }
+
+    return QuotaManager::IsShuttingDown();
+  }
+
+  static bool
+  IsShuttingDownOnNonBackgroundThread()
+  {
+    MOZ_ASSERT(!IsOnBackgroundThread());
+
+    return QuotaManager::IsShuttingDown();
+  }
+
+  bool
+  IsShuttingDown() const
+  {
+    AssertIsOnBackgroundThread();
+
+    return mShutdownRequested;
+  }
+
   NS_INLINE_DECL_REFCOUNTING(Client, override)
 
   Type
   GetType() override;
 
   nsresult
   InitOrigin(PersistenceType aPersistenceType,
              const nsACString& aGroup,
@@ -286,17 +320,17 @@ public:
 
   void
   StopIdleMaintenance() override;
 
   void
   ShutdownWorkThreads() override;
 
 private:
-  ~Client() override = default;
+  ~Client() override;
 };
 
 // FileDescriptorHolder owns a file descriptor and its memory mapping.
 // FileDescriptorHolder is derived by two runnable classes (that is,
 // (Parent|Child)Runnable.
 class FileDescriptorHolder : public Runnable
 {
 public:
@@ -1093,16 +1127,20 @@ FindHashMatch(const Metadata& aMetadata,
 
 PAsmJSCacheEntryParent*
 AllocEntryParent(OpenMode aOpenMode,
                  WriteParams aWriteParams,
                  const PrincipalInfo& aPrincipalInfo)
 {
   AssertIsOnBackgroundThread();
 
+  if (NS_WARN_IF(Client::IsShuttingDownOnBackgroundThread())) {
+    return nullptr;
+  }
+
   if (NS_WARN_IF(aPrincipalInfo.type() == PrincipalInfo::TNullPrincipalInfo)) {
     MOZ_ASSERT(false);
     return nullptr;
   }
 
   RefPtr<ParentRunnable> runnable =
     new ParentRunnable(aPrincipalInfo, aOpenMode, aWriteParams);
 
@@ -1646,16 +1684,35 @@ CloseEntryForWrite(size_t aSize,
     *(AsmJSCookieType*)childRunnable->MappedMemory() = sAsmJSCookie;
   }
 }
 
 /*******************************************************************************
  * Client
  ******************************************************************************/
 
+Client* Client::sInstance = nullptr;
+
+Client::Client()
+  : mShutdownRequested(false)
+{
+  AssertIsOnBackgroundThread();
+  MOZ_ASSERT(!sInstance, "We expect this to be a singleton!");
+
+  sInstance = this;
+}
+
+Client::~Client()
+{
+  AssertIsOnBackgroundThread();
+  MOZ_ASSERT(sInstance == this, "We expect this to be a singleton!");
+
+  sInstance = nullptr;
+}
+
 Client::Type
 Client::GetType()
 {
   return ASMJS;
 }
 
 nsresult
 Client::InitOrigin(PersistenceType aPersistenceType,