From a3ddeba4a795ef7b125ae21e812c52933fa1796f Mon Sep 17 00:00:00 2001 From: Bill McCloskey Date: Mon, 13 Jul 2015 14:14:13 -0700 Subject: [PATCH] Bug 1191143 - Cancel CPOWs from both sides (r=dvander) --- ipc/glue/MessageChannel.cpp | 19 +++++++++++-------- ipc/glue/MessageChannel.h | 2 +- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/ipc/glue/MessageChannel.cpp b/ipc/glue/MessageChannel.cpp index 9341ba5cdef..87bc69db644 100644 --- a/ipc/glue/MessageChannel.cpp +++ b/ipc/glue/MessageChannel.cpp @@ -106,7 +106,7 @@ struct RunnableMethodTraits DebugAbort(__FILE__, __LINE__, #_cond,## __VA_ARGS__); \ } while (0) -static MessageChannel* gParentProcessBlocker; +static MessageChannel* gMainThreadBlocker; namespace mozilla { namespace ipc { @@ -404,8 +404,8 @@ MessageChannel::Clear() // In practice, mListener owns the channel, so the channel gets deleted // before mListener. But just to be safe, mListener is a weak pointer. - if (gParentProcessBlocker == this) { - gParentProcessBlocker = nullptr; + if (gMainThreadBlocker == this) { + gMainThreadBlocker = nullptr; } mDequeueOneTask->Cancel(); @@ -1334,7 +1334,7 @@ MessageChannel::DispatchSyncMessage(const Message& aMsg, Message*& aReply) MaybeScriptBlocker scriptBlocker(this, prio > IPC::Message::PRIORITY_NORMAL); MessageChannel* dummy; - MessageChannel*& blockingVar = ShouldBlockScripts() ? gParentProcessBlocker : dummy; + MessageChannel*& blockingVar = NS_IsMainThread() ? gMainThreadBlocker : dummy; Result rv; if (mTimedOutMessageSeqno && mTimedOutMessagePriority >= prio) { @@ -2046,22 +2046,25 @@ MessageChannel::CancelCurrentTransactionInternal() // see if mCurrentTransaction is 0 before examining DispatchSyncMessage. } -void +bool MessageChannel::CancelCurrentTransaction() { MonitorAutoLock lock(*mMonitor); - if (mCurrentTransaction) { + if (mCurrentTransaction && + (DispatchingSyncMessagePriority() >= IPC::Message::PRIORITY_HIGH)) + { CancelCurrentTransactionInternal(); mLink->SendMessage(new CancelMessage()); + return true; } + return false; } void CancelCPOWs() { - if (gParentProcessBlocker) { + if (gMainThreadBlocker && gMainThreadBlocker->CancelCurrentTransaction()) { mozilla::Telemetry::Accumulate(mozilla::Telemetry::IPC_TRANSACTION_CANCEL, true); - gParentProcessBlocker->CancelCurrentTransaction(); } } diff --git a/ipc/glue/MessageChannel.h b/ipc/glue/MessageChannel.h index 17230973340..3aad5d8064c 100644 --- a/ipc/glue/MessageChannel.h +++ b/ipc/glue/MessageChannel.h @@ -143,7 +143,7 @@ class MessageChannel : HasResultCodes return !mCxxStackFrames.empty(); } - void CancelCurrentTransaction(); + bool CancelCurrentTransaction(); /** * This function is used by hang annotation code to determine which IPDL