diff --git a/xpcom/threads/nsThread.cpp b/xpcom/threads/nsThread.cpp index ed57d8d74a0e..16d262893ecd 100644 --- a/xpcom/threads/nsThread.cpp +++ b/xpcom/threads/nsThread.cpp @@ -588,6 +588,7 @@ nsThread::nsThread(NotNull aQueue, mShutdownRequired(false), mPriority(PRIORITY_NORMAL), mIsMainThread(aMainThread == MAIN_THREAD), + mUseHangMonitor(aMainThread == MAIN_THREAD), mIsAPoolThreadFree(nullptr), mCanInvokeJS(false), #ifdef EARLY_BETA_OR_EARLIER @@ -606,6 +607,7 @@ nsThread::nsThread() mShutdownRequired(false), mPriority(PRIORITY_NORMAL), mIsMainThread(false), + mUseHangMonitor(false), mCanInvokeJS(false), #ifdef EARLY_BETA_OR_EARLIER mLastWakeupCheckTime(TimeStamp::Now()), @@ -1077,8 +1079,13 @@ nsThread::ProcessNextEvent(bool aMayWait, bool* aResult) { } Maybe noJSAPI; + + if (mUseHangMonitor && reallyWait) { + BackgroundHangMonitor().NotifyWait(); + } + if (mIsMainThread) { - DoMainThreadSpecificProcessing(reallyWait); + DoMainThreadSpecificProcessing(); } ++mNestedEventLoopDepth; @@ -1155,7 +1162,7 @@ nsThread::ProcessNextEvent(bool aMayWait, bool* aResult) { mozilla::TimeStamp now = mozilla::TimeStamp::Now(); - if (mIsMainThread) { + if (mUseHangMonitor) { BackgroundHangMonitor().NotifyActivity(); } @@ -1352,15 +1359,11 @@ void nsThread::SetScriptObserver( mScriptObserver = aScriptObserver; } -void nsThread::DoMainThreadSpecificProcessing(bool aReallyWait) const { +void nsThread::DoMainThreadSpecificProcessing() const { MOZ_ASSERT(mIsMainThread); ipc::CancelCPOWs(); - if (aReallyWait) { - BackgroundHangMonitor().NotifyWait(); - } - // Fire a memory pressure notification, if one is pending. if (!ShuttingDown()) { MemoryPressureState mpPending = NS_GetPendingMemoryPressure(); diff --git a/xpcom/threads/nsThread.h b/xpcom/threads/nsThread.h index fcde82df2402..ac00535323cd 100644 --- a/xpcom/threads/nsThread.h +++ b/xpcom/threads/nsThread.h @@ -257,8 +257,13 @@ class nsThread : public nsIThreadInternal, // notifications, etc. nsLocalExecutionRecord EnterLocalExecution(); + void SetUseHangMonitor(bool aValue) { + MOZ_ASSERT(IsOnCurrentThread()); + mUseHangMonitor = aValue; + } + private: - void DoMainThreadSpecificProcessing(bool aReallyWait) const; + void DoMainThreadSpecificProcessing() const; protected: friend class nsThreadShutdownEvent; @@ -329,6 +334,7 @@ class nsThread : public nsIThreadInternal, int8_t mPriority; const bool mIsMainThread; + bool mUseHangMonitor; mozilla::Atomic* mIsAPoolThreadFree; // Set to true if this thread creates a JSRuntime.