Bug 1341924 - Don't attempt to dispatch CheckResponsivenessTasks to non-main threads. r?njn draft
authorMarkus Stange <mstange@themasta.com>
Mon, 13 Mar 2017 20:44:15 -0400
changeset 498497 a61899ab1d20c7b07530aff1d0a61f02b4967f51
parent 498496 00100312ceaab4cdf6ef0a9715f32d57ac6c582e
child 549170 1b6607f1c9a59f628ef096a7fdb2430477ea7137
push id49212
push userbmo:mstange@themasta.com
push dateTue, 14 Mar 2017 21:27:29 +0000
reviewersnjn
bugs1341924, 1340714
milestone55.0a1
Bug 1341924 - Don't attempt to dispatch CheckResponsivenessTasks to non-main threads. r?njn This is more of a workaround than a real fix, but the old code wasn't working for non-main threads either, and we'd like to change the way this information is computed anyway (bug 1340714) and then we won't need CheckResponsivenessTask any more. MozReview-Commit-ID: FGiomjwpk3z
tools/profiler/gecko/ThreadResponsiveness.cpp
tools/profiler/gecko/ThreadResponsiveness.h
--- a/tools/profiler/gecko/ThreadResponsiveness.cpp
+++ b/tools/profiler/gecko/ThreadResponsiveness.cpp
@@ -26,16 +26,18 @@ public:
   }
 
 protected:
   ~CheckResponsivenessTask()
   {
   }
 
 public:
+
+  // Can only run on the main thread.
   NS_IMETHOD Run() override
   {
     MonitorAutoLock mon(mMonitor);
     if (mStop)
       return NS_OK;
 
     // This is raced on because we might pause the thread here
     // for profiling so if we tried to use a monitor to protect
@@ -90,23 +92,20 @@ ThreadResponsiveness::~ThreadResponsiven
   if (mActiveTracerEvent) {
     mActiveTracerEvent->Terminate();
   }
 }
 
 void
 ThreadResponsiveness::Update(bool aIsMainThread, nsIThread* aThread)
 {
-  if (!mActiveTracerEvent) {
-    if (aIsMainThread) {
-      mActiveTracerEvent = new CheckResponsivenessTask();
-      NS_DispatchToMainThread(mActiveTracerEvent);
-    } else if (aThread) {
-      mActiveTracerEvent = new CheckResponsivenessTask();
-      aThread->Dispatch(mActiveTracerEvent, NS_DISPATCH_NORMAL);
-    }
+  if (!aIsMainThread) {
+    return;
   }
 
-  if (mActiveTracerEvent) {
-    mLastTracerTime = mActiveTracerEvent->GetLastTracerTime();
+  if (!mActiveTracerEvent) {
+    mActiveTracerEvent = new CheckResponsivenessTask();
+    NS_DispatchToMainThread(mActiveTracerEvent);
   }
+
+  mLastTracerTime = mActiveTracerEvent->GetLastTracerTime();
 }
 
--- a/tools/profiler/gecko/ThreadResponsiveness.h
+++ b/tools/profiler/gecko/ThreadResponsiveness.h
@@ -13,16 +13,17 @@
 class CheckResponsivenessTask;
 
 class ThreadResponsiveness {
 public:
   explicit ThreadResponsiveness();
 
   ~ThreadResponsiveness();
 
+  // Won't do anything on non-main threads for now.
   void Update(bool aIsMainThread, nsIThread* aThread);
 
   mozilla::TimeDuration GetUnresponsiveDuration(const mozilla::TimeStamp& now) const {
     return now - mLastTracerTime;
   }
 
   bool HasData() const {
     return !mLastTracerTime.IsNull();