Bug 1426061. P2 - offload MediaCacheStream::Close() to another thread. r=bechen,gerald

So we won't take the cache lock on the main thread.

MozReview-Commit-ID: KYSB0vonOZ2

--HG--
extra : rebase_source : 142884bb450a5469b2634a676ce2d4f3c1790954
extra : intermediate-source : 0911c55511374cd19719743531c136fc122e4ab0
extra : source : 2f46a7eddea484fc5dec773d9d57896e524e014d
This commit is contained in:
JW Wang 2017-12-15 10:29:29 +08:00
parent 32de19ef80
commit 61603d61fe
2 changed files with 19 additions and 8 deletions

View File

@ -2377,8 +2377,19 @@ MediaCacheStream::Close()
if (!mMediaCache) {
return;
}
OwnerThread()->Dispatch(NS_NewRunnableFunction(
"MediaCacheStream::Close",
[ this, client = RefPtr<ChannelMediaResource>(mClient) ]() {
AutoLock lock(mMediaCache->Monitor());
CloseInternal(lock);
}));
}
void
MediaCacheStream::CloseInternal(AutoLock& aLock)
{
MOZ_ASSERT(OwnerThread()->IsOnCurrentThread());
AutoLock lock(mMediaCache->Monitor());
if (mClosed) {
return;
}
@ -2386,17 +2397,15 @@ MediaCacheStream::Close()
// Closing a stream will change the return value of
// MediaCacheStream::AreAllStreamsForResourceSuspended as well as
// ChannelMediaResource::IsSuspendedByCache. Let's notify it.
mMediaCache->QueueSuspendedStatusUpdate(lock, mResourceID);
mMediaCache->QueueSuspendedStatusUpdate(aLock, mResourceID);
mClosed = true;
mMediaCache->ReleaseStreamBlocks(lock, this);
mMediaCache->ReleaseStreamBlocks(aLock, this);
// Wake up any blocked readers
lock.NotifyAll();
aLock.NotifyAll();
// Queue an Update since we may have created more free space. Don't do
// it from CloseInternal since that gets called by Update() itself
// sometimes, and we try to not to queue updates from Update().
mMediaCache->QueueUpdate(lock);
// Queue an Update since we may have created more free space.
mMediaCache->QueueUpdate(aLock);
}
void

View File

@ -465,6 +465,8 @@ private:
void UpdateDownloadStatistics(AutoLock&);
void CloseInternal(AutoLock&);
// Instance of MediaCache to use with this MediaCacheStream.
RefPtr<MediaCache> mMediaCache;