Skip to content

Commit

Permalink
Bug 1412181 - add a proxy to be registered with ClearOnShutdown() to …
Browse files Browse the repository at this point in the history
…clear MediaCache::sThread. r=gerald

MozReview-Commit-ID: 9SXSKTP9Twb
  • Loading branch information
jwwang committed Oct 27, 2017
1 parent 4bf3465 commit 1d2ef6a
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions dom/media/MediaCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,15 +268,6 @@ class MediaCache
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)
Expand Down Expand Up @@ -726,10 +717,18 @@ MediaCache::GetMediaCache(int64_t aContentLength)
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) {
Expand Down

0 comments on commit 1d2ef6a

Please sign in to comment.