Bug 1428242. P2 - MediaCache::ReadCacheFile() doesn't need to drop the cache monitor. draft
authorJW Wang <jwwang@mozilla.com>
Fri, 05 Jan 2018 10:48:14 +0800
changeset 716098 e5489e86f5debf8d2ff0b96b81a8d0c20eab7c0e
parent 716068 cda450621750c15c3d5ca539c7192f1d3b4c0efe
child 716099 aeab8a218ab098a7d7cbe60c44829e17ac5428e6
push id94337
push userjwwang@mozilla.com
push dateFri, 05 Jan 2018 06:34:48 +0000
bugs1428242, 1354389
milestone59.0a1
Bug 1428242. P2 - MediaCache::ReadCacheFile() doesn't need to drop the cache monitor. Since we now never take the lock on the main thread, we can safely do file IO while holding the lock without blocking the main thread. This reverts the change of Bug 1354389 P1. MozReview-Commit-ID: EhEwTjINQIT
dom/media/MediaCache.cpp
--- a/dom/media/MediaCache.cpp
+++ b/dom/media/MediaCache.cpp
@@ -810,27 +810,20 @@ MediaCache::GetMediaCache(int64_t aConte
 
 nsresult
 MediaCache::ReadCacheFile(AutoLock&,
                           int64_t aOffset,
                           void* aData,
                           int32_t aLength,
                           int32_t* aBytes)
 {
-  RefPtr<MediaBlockCacheBase> blockCache = mBlockCache;
-  if (!blockCache) {
+  if (!mBlockCache) {
     return NS_ERROR_FAILURE;
   }
-  {
-    // Since the monitor might be acquired on the main thread, we need to drop
-    // the monitor while doing IO in order not to block the main thread.
-    AutoUnlock unlock(mMonitor);
-    return blockCache->Read(
-      aOffset, reinterpret_cast<uint8_t*>(aData), aLength, aBytes);
-  }
+  return mBlockCache->Read(aOffset, reinterpret_cast<uint8_t*>(aData), aLength, aBytes);
 }
 
 // Allowed range is whatever can be accessed with an int32_t block index.
 static bool
 IsOffsetAllowed(int64_t aOffset)
 {
   return aOffset < (int64_t(INT32_MAX) + 1) * MediaCache::BLOCK_SIZE &&
          aOffset >= 0;