Bug 1412181 - add a proxy to be registered with ClearOnShutdown() to clear MediaCache::sThread.
MozReview-Commit-ID: 9SXSKTP9Twb
--- a/dom/media/MediaCache.cpp
+++ b/dom/media/MediaCache.cpp
@@ -264,25 +264,16 @@ public:
return nullptr;
}
private:
MediaCache* mMediaCache;
int64_t mResourceID;
uint32_t mNext;
};
- // Called during shutdown to clear sThread.
- void operator=(std::nullptr_t)
- {
- nsCOMPtr<nsIThread> thread = sThread.forget();
- if (thread) {
- thread->Shutdown();
- }
- }
-
protected:
explicit MediaCache(MediaBlockCacheBase* aCache)
: mNextResourceID(1)
, mReentrantMonitor("MediaCache.mReentrantMonitor")
, mBlockCache(aCache)
, mUpdateQueued(false)
#ifdef DEBUG
, mInUpdate(false)
@@ -722,20 +713,28 @@ MediaCache::GetMediaCache(int64_t aConte
sThreadInit = true;
nsCOMPtr<nsIThread> thread;
nsresult rv = NS_NewNamedThread("MediaCache", getter_AddRefs(thread));
if (NS_FAILED(rv)) {
NS_WARNING("Failed to create a thread for MediaCache.");
return nullptr;
}
sThread = thread.forget();
- // Note it is safe to pass an invalid pointer for operator=(std::nullptr_t)
- // is non-virtual and it will not access |this|.
- ClearOnShutdown(reinterpret_cast<MediaCache*>(0x1),
- ShutdownPhase::ShutdownThreads);
+
+ static struct ClearThread
+ {
+ // Called during shutdown to clear sThread.
+ void operator=(std::nullptr_t)
+ {
+ nsCOMPtr<nsIThread> thread = sThread.forget();
+ MOZ_ASSERT(thread);
+ thread->Shutdown();
+ }
+ } sClearThread;
+ ClearOnShutdown(&sClearThread, ShutdownPhase::ShutdownThreads);
}
if (!sThread) {
return nullptr;
}
if (aContentLength > 0 &&
aContentLength <= int64_t(MediaPrefs::MediaMemoryCacheMaxSize()) * 1024) {