From e4a543d886a9608f9c2aec906e0b7cbc54472648 Mon Sep 17 00:00:00 2001 From: John Lin Date: Tue, 22 Jan 2019 22:55:58 +0000 Subject: [PATCH] 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 --HG-- extra : moz-landing-system : lando --- dom/media/hls/HLSDecoder.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/dom/media/hls/HLSDecoder.cpp b/dom/media/hls/HLSDecoder.cpp index a3807db6a25d..3d34ed38a047 100644 --- a/dom/media/hls/HLSDecoder.cpp +++ b/dom/media/hls/HLSDecoder.cpp @@ -52,6 +52,7 @@ HLSResourceCallbacksSupport::HLSResourceCallbacksSupport(HLSDecoder* aDecoder) } void HLSResourceCallbacksSupport::Detach() { + MOZ_ASSERT(NS_IsMainThread()); MutexAutoLock lock(mMutex); mDecoder = nullptr; } @@ -65,7 +66,6 @@ void HLSResourceCallbacksSupport::OnDataArrived() { RefPtr self = this; NS_DispatchToMainThread(NS_NewRunnableFunction( "HLSResourceCallbacksSupport::OnDataArrived", [self]() -> void { - MutexAutoLock lock(self->mMutex); if (self->mDecoder) { self->mDecoder->NotifyDataArrived(); } @@ -80,8 +80,7 @@ void HLSResourceCallbacksSupport::OnError(int aErrorCode) { } RefPtr 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.