Bug 1368296 - Renaming WorkerProxyToMainThreadRunnable::RunBackOnWorkerThread to RunBackOnWorkerThreadForCleanup and improving the description for this method, r=asuth
authorAndrea Marchesini <amarchesini@mozilla.com>
Fri, 02 Jun 2017 11:05:27 +0200
changeset 362004 34b63eb52b4d4ee331ddb3f91f3feb06adfea5c2
parent 362003 db0bd0d1b8fdd78de2132c4f005e6005ea7a39ce
child 362005 7ba5835bb00f43d5ef2e9c31d38b23a9094f5fdc
push id31955
push userryanvm@gmail.com
push dateFri, 02 Jun 2017 15:10:12 +0000
treeherdermozilla-central@95d2d23ff510 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersasuth
bugs1368296
milestone55.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 1368296 - Renaming WorkerProxyToMainThreadRunnable::RunBackOnWorkerThread to RunBackOnWorkerThreadForCleanup and improving the description for this method, r=asuth
dom/bindings/BindingUtils.cpp
dom/console/Console.cpp
dom/workers/WorkerRunnable.cpp
dom/workers/WorkerRunnable.h
--- a/dom/bindings/BindingUtils.cpp
+++ b/dom/bindings/BindingUtils.cpp
@@ -3617,17 +3617,17 @@ private:
 
     nsPIDOMWindowInner* window = wp->GetWindow();
     if (window && window->GetExtantDoc()) {
       window->GetExtantDoc()->WarnOnceAbout(mOperation);
     }
   }
 
   void
-  RunBackOnWorkerThread() override
+  RunBackOnWorkerThreadForCleanup() override
   {}
 };
 
 } // anonymous namespace
 
 void
 DeprecationWarning(JSContext* aCx, JSObject* aObject,
                    nsIDocument::DeprecatedOperations aOperation)
--- a/dom/console/Console.cpp
+++ b/dom/console/Console.cpp
@@ -332,22 +332,22 @@ public:
   }
 
   bool
   Dispatch(JSContext* aCx)
   {
     mWorkerPrivate->AssertIsOnWorkerThread();
 
     if (NS_WARN_IF(!PreDispatch(aCx))) {
-      RunBackOnWorkerThread();
+      RunBackOnWorkerThreadForCleanup();
       return false;
     }
 
     if (NS_WARN_IF(!WorkerProxyToMainThreadRunnable::Dispatch())) {
-      // RunBackOnWorkerThread() will be called by
+      // RunBackOnWorkerThreadForCleanup() will be called by
       // WorkerProxyToMainThreadRunnable::Dispatch().
       return false;
     }
 
     return true;
   }
 
 protected:
@@ -416,17 +416,17 @@ protected:
     global = js::UncheckedUnwrap(global);
 
     JSAutoCompartment ac(cx, global);
 
     RunConsole(cx, nullptr, nullptr);
   }
 
   void
-  RunBackOnWorkerThread() override
+  RunBackOnWorkerThreadForCleanup() override
   {
     mWorkerPrivate->AssertIsOnWorkerThread();
     ReleaseData();
     mConsole = nullptr;
   }
 
   // This method is called in the owning thread of the Console object.
   virtual bool
--- a/dom/workers/WorkerRunnable.cpp
+++ b/dom/workers/WorkerRunnable.cpp
@@ -672,23 +672,23 @@ WorkerProxyToMainThreadRunnable::~Worker
 {}
 
 bool
 WorkerProxyToMainThreadRunnable::Dispatch()
 {
   mWorkerPrivate->AssertIsOnWorkerThread();
 
   if (NS_WARN_IF(!HoldWorker())) {
-    RunBackOnWorkerThread();
+    RunBackOnWorkerThreadForCleanup();
     return false;
   }
 
   if (NS_WARN_IF(NS_FAILED(mWorkerPrivate->DispatchToMainThread(this)))) {
     ReleaseWorker();
-    RunBackOnWorkerThread();
+    RunBackOnWorkerThreadForCleanup();
     return false;
   }
 
   return true;
 }
 
 NS_IMETHODIMP
 WorkerProxyToMainThreadRunnable::Run()
@@ -710,32 +710,33 @@ WorkerProxyToMainThreadRunnable::PostDis
     ReleaseRunnable(WorkerPrivate* aWorkerPrivate,
                     WorkerProxyToMainThreadRunnable* aRunnable)
       : MainThreadWorkerControlRunnable(aWorkerPrivate)
       , mRunnable(aRunnable)
     {
       MOZ_ASSERT(aRunnable);
     }
 
-    // We must call RunBackOnWorkerThread() also if the runnable is canceled.
+    // We must call RunBackOnWorkerThreadForCleanup() also if the runnable is
+    // canceled.
     nsresult
     Cancel() override
     {
       WorkerRun(nullptr, mWorkerPrivate);
       return MainThreadWorkerControlRunnable::Cancel();
     }
 
     virtual bool
     WorkerRun(JSContext* aCx, workers::WorkerPrivate* aWorkerPrivate) override
     {
       MOZ_ASSERT(aWorkerPrivate);
       aWorkerPrivate->AssertIsOnWorkerThread();
 
       if (mRunnable) {
-        mRunnable->RunBackOnWorkerThread();
+        mRunnable->RunBackOnWorkerThreadForCleanup();
 
         // Let's release the worker thread.
         mRunnable->ReleaseWorker();
         mRunnable = nullptr;
       }
 
       return true;
     }
--- a/dom/workers/WorkerRunnable.h
+++ b/dom/workers/WorkerRunnable.h
@@ -410,28 +410,34 @@ public:
 
 private:
   NS_IMETHOD Run() override;
 };
 
 // This runnable is an helper class for dispatching something from a worker
 // thread to the main-thread and back to the worker-thread. During this
 // operation, this class will keep the worker alive.
+// The purpose of RunBackOnWorkerThreadForCleanup() must be used, as the name
+// says, only to release resources, no JS has to be executed, no timers, or
+// other things. The reason of such limitations is that, in order to execute
+// this method in any condition (also when the worker is shutting down), a
+// Control Runnable is used, and, this could generate a reordering of existing
+// runnables.
 class WorkerProxyToMainThreadRunnable : public Runnable
 {
 protected:
   explicit WorkerProxyToMainThreadRunnable(WorkerPrivate* aWorkerPrivate);
 
   virtual ~WorkerProxyToMainThreadRunnable();
 
   // First this method is called on the main-thread.
   virtual void RunOnMainThread() = 0;
 
   // After this second method is called on the worker-thread.
-  virtual void RunBackOnWorkerThread() = 0;
+  virtual void RunBackOnWorkerThreadForCleanup() = 0;
 
 public:
   bool Dispatch();
 
 private:
   NS_IMETHOD Run() override;
 
   void PostDispatchOnMainThread();