Bug 1405290 - Improve logging of workers when shutting down - part 1 - WorkerHolder must assert in release, r=asuth
authorAndrea Marchesini <amarchesini@mozilla.com>
Wed, 15 Nov 2017 07:58:38 +0100
changeset 391954 3d7896bf89f74163c53332640806fe2bbc46acbc
parent 391953 45352aa4319debd6ad3445f2729db197ffc83eac
child 391955 bb508b270fab5a74c12270da0dd736ade0914659
push id32909
push usercbrindusan@mozilla.com
push dateWed, 15 Nov 2017 22:25:14 +0000
treeherdermozilla-central@f41930a869a8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersasuth
bugs1405290
milestone59.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 1405290 - Improve logging of workers when shutting down - part 1 - WorkerHolder must assert in release, r=asuth
dom/workers/WorkerHolder.cpp
dom/workers/WorkerHolder.h
--- a/dom/workers/WorkerHolder.cpp
+++ b/dom/workers/WorkerHolder.cpp
@@ -4,63 +4,76 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "WorkerHolder.h"
 #include "WorkerPrivate.h"
 
 BEGIN_WORKERS_NAMESPACE
 
+namespace {
+
+void
+AssertOnOwningThread(void* aThread)
+{
+  if (MOZ_UNLIKELY(aThread != GetCurrentVirtualThread())) {
+    MOZ_CRASH_UNSAFE_OOL("WorkerHolder on the wrong thread.");
+  }
+}
+
+} // anonymous
+
 WorkerHolder::WorkerHolder(Behavior aBehavior)
   : mWorkerPrivate(nullptr)
   , mBehavior(aBehavior)
+  , mThread(GetCurrentVirtualThread())
 {
 }
 
 WorkerHolder::~WorkerHolder()
 {
-  NS_ASSERT_OWNINGTHREAD(WorkerHolder);
+  AssertOnOwningThread(mThread);
   ReleaseWorkerInternal();
   MOZ_ASSERT(mWorkerPrivate == nullptr);
 }
 
 bool
 WorkerHolder::HoldWorker(WorkerPrivate* aWorkerPrivate, Status aFailStatus)
 {
-  NS_ASSERT_OWNINGTHREAD(WorkerHolder);
+  AssertOnOwningThread(mThread);
   MOZ_ASSERT(aWorkerPrivate);
   aWorkerPrivate->AssertIsOnWorkerThread();
 
   if (!aWorkerPrivate->AddHolder(this, aFailStatus)) {
     return false;
   }
 
   mWorkerPrivate = aWorkerPrivate;
   return true;
 }
 
 void
 WorkerHolder::ReleaseWorker()
 {
-  NS_ASSERT_OWNINGTHREAD(WorkerHolder);
+  AssertOnOwningThread(mThread);
   MOZ_ASSERT(mWorkerPrivate);
 
   ReleaseWorkerInternal();
 }
 
 WorkerHolder::Behavior
 WorkerHolder::GetBehavior() const
 {
   return mBehavior;
 }
 
 void
 WorkerHolder::ReleaseWorkerInternal()
 {
-  NS_ASSERT_OWNINGTHREAD(WorkerHolder);
+  AssertOnOwningThread(mThread);
 
   if (mWorkerPrivate) {
     mWorkerPrivate->AssertIsOnWorkerThread();
     mWorkerPrivate->RemoveHolder(this);
     mWorkerPrivate = nullptr;
   }
 }
 
--- a/dom/workers/WorkerHolder.h
+++ b/dom/workers/WorkerHolder.h
@@ -67,18 +67,16 @@ enum Status
 
   // The close handler has run and the worker is effectively dead.
   Dead
 };
 
 class WorkerHolder
 {
 public:
-  NS_DECL_OWNINGTHREAD
-
   enum Behavior {
     AllowIdleShutdownStart,
     PreventIdleShutdownStart,
   };
 
   explicit WorkerHolder(Behavior aBehavior = PreventIdleShutdownStart);
   virtual ~WorkerHolder();
 
@@ -93,13 +91,16 @@ protected:
   void ReleaseWorkerInternal();
 
   WorkerPrivate* MOZ_NON_OWNING_REF mWorkerPrivate;
 
 private:
   void AssertIsOwningThread() const;
 
   const Behavior mBehavior;
+
+  // For debugging only.
+  void* mThread;
 };
 
 END_WORKERS_NAMESPACE
 
 #endif /* mozilla_dom_workers_WorkerHolder_h */