Bug 1517252 - p1: don't lock HLSResourceCallbacksSupport mutex unnecessarily. r=jya
authorJohn Lin <jolin@mozilla.com>
Tue, 22 Jan 2019 22:55:58 +0000
changeset 515196 bec07b59907f2dad66ce976e67cc5adc8bf961fa
parent 515195 b6f80451898e0878e3299e5ea949f9c81dfce770
child 515197 e3dee65958a3ebe2c0f1fcec48bc896e5ffbefb6
push id1953
push userffxbld-merge
push dateMon, 11 Mar 2019 12:10:20 +0000
treeherdermozilla-release@9c35dcbaa899 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjya
bugs1517252
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1517252 - p1: don't lock HLSResourceCallbacksSupport mutex unnecessarily. r=jya HLSResourceCallbacksSupport::mDecoder is cleared on main thread too, so the nullness check already ensures decoder methods won't be called after shut down. In fact, for OnError() the lock is harmful because the task calls MediaDecoder::NetworkError(), which triggers decoder shutdown and eventually HLSResourceCallbacksSupport::Detach(), which tries to lock the mutex again while the mutex is still locked. Differential Revision: https://phabricator.services.mozilla.com/D16709
dom/media/hls/HLSDecoder.cpp
--- a/dom/media/hls/HLSDecoder.cpp
+++ b/dom/media/hls/HLSDecoder.cpp
@@ -47,46 +47,45 @@ class HLSResourceCallbacksSupport
 };
 
 HLSResourceCallbacksSupport::HLSResourceCallbacksSupport(HLSDecoder* aDecoder)
     : mMutex("HLSResourceCallbacksSupport"), mDecoder(aDecoder) {
   MOZ_ASSERT(mDecoder);
 }
 
 void HLSResourceCallbacksSupport::Detach() {
+  MOZ_ASSERT(NS_IsMainThread());
   MutexAutoLock lock(mMutex);
   mDecoder = nullptr;
 }
 
 void HLSResourceCallbacksSupport::OnDataArrived() {
   HLS_DEBUG("HLSResourceCallbacksSupport", "OnDataArrived.");
   MutexAutoLock lock(mMutex);
   if (!mDecoder) {
     return;
   }
   RefPtr<HLSResourceCallbacksSupport> self = this;
   NS_DispatchToMainThread(NS_NewRunnableFunction(
       "HLSResourceCallbacksSupport::OnDataArrived", [self]() -> void {
-        MutexAutoLock lock(self->mMutex);
         if (self->mDecoder) {
           self->mDecoder->NotifyDataArrived();
         }
       }));
 }
 
 void HLSResourceCallbacksSupport::OnError(int aErrorCode) {
   HLS_DEBUG("HLSResourceCallbacksSupport", "onError(%d)", aErrorCode);
   MutexAutoLock lock(mMutex);
   if (!mDecoder) {
     return;
   }
   RefPtr<HLSResourceCallbacksSupport> self = this;
   NS_DispatchToMainThread(NS_NewRunnableFunction(
-      "HLSResourceCallbacksSupport::OnDataArrived", [self]() -> void {
-        MutexAutoLock lock(self->mMutex);
+      "HLSResourceCallbacksSupport::OnError", [self]() -> void {
         if (self->mDecoder) {
           // Since HLS source should be from the Internet, we treat all resource
           // errors from GeckoHlsPlayer as network errors.
           self->mDecoder->NetworkError(
               MediaResult(NS_ERROR_FAILURE, "HLS error"));
         }
       }));
 }