Bug 1428951 - add a getter for MediaCacheStream::GetDebugInfo() to take the cache monitor on the main thread.
MozReview-Commit-ID: 8qkZg0MJsGQ
--- a/dom/media/MediaCache.cpp
+++ b/dom/media/MediaCache.cpp
@@ -467,16 +467,26 @@ protected:
// A list of resource IDs to notify about the change in suspended status.
nsTArray<int64_t> mSuspendedStatusToNotify;
// The thread on which we will run data callbacks from the channels.
// Note this thread is shared among all MediaCache instances.
static StaticRefPtr<nsIThread> sThread;
// True if we've tried to init sThread. Note we try once only so it is safe
// to access sThread on all threads.
static bool sThreadInit;
+
+private:
+ // Used by MediaCacheStream::GetDebugInfo() only for debugging.
+ // Don't add new callers to this function.
+ friend nsCString MediaCacheStream::GetDebugInfo();
+ mozilla::Monitor& GetMonitorOnTheMainThread()
+ {
+ MOZ_DIAGNOSTIC_ASSERT(NS_IsMainThread());
+ return mMonitor;
+ }
};
// Initialized to nullptr by non-local static initialization.
/* static */ MediaCache* MediaCache::gMediaCache;
/* static */ StaticRefPtr<nsIThread> MediaCache::sThread;
/* static */ bool MediaCache::sThreadInit = false;
@@ -2979,17 +2989,17 @@ MediaCacheStream::GetDownloadRate(bool*
MOZ_ASSERT(!NS_IsMainThread());
AutoLock lock(mMediaCache->Monitor());
return mDownloadStatistics.GetRate(aIsReliable);
}
nsCString
MediaCacheStream::GetDebugInfo()
{
- AutoLock lock(mMediaCache->Monitor());
+ AutoLock lock(mMediaCache->GetMonitorOnTheMainThread());
return nsPrintfCString("mStreamLength=%" PRId64 " mChannelOffset=%" PRId64
" mCacheSuspended=%d mChannelEnded=%d mLoadID=%u",
mStreamLength,
mChannelOffset,
mCacheSuspended,
mChannelEnded,
mLoadID);
}