Bug 1485722 - Improve thread assertions in EventSourceImpl. r=smaug.
authorHenri Sivonen <hsivonen@hsivonen.fi>
Fri, 24 Aug 2018 13:12:54 +0300
changeset 491839 9b452b8c8d137f8f030f31351be89887a82ffca7
parent 491838 1c7e3f8af2e33ed2321a715f6381bac48ca678d9
child 491840 5b7d48d3b1437b49093a18887640c83ca0b68f3a
push id1815
push userffxbld-merge
push dateMon, 15 Oct 2018 10:40:45 +0000
treeherdermozilla-release@18d4c09e9378 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1485722
milestone63.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 1485722 - Improve thread assertions in EventSourceImpl. r=smaug. MozReview-Commit-ID: Aq7vVSronYg Differential Revision: https://phabricator.services.mozilla.com/D4245
dom/base/EventSource.cpp
--- a/dom/base/EventSource.cpp
+++ b/dom/base/EventSource.cpp
@@ -149,17 +149,17 @@ public:
 
   void AssertIsOnTargetThread() const
   {
     MOZ_ASSERT(IsTargetThread());
   }
 
   bool IsTargetThread() const
   {
-    return NS_IsMainThread() == mIsMainThread;
+    return NS_GetCurrentThread() == mTargetThread;
   }
 
   uint16_t ReadyState()
   {
     MutexAutoLock lock(mMutex);
     if (mEventSource) {
       return mEventSource->mReadyState;
     }
@@ -307,16 +307,24 @@ public:
   // These attributes are used for error reporting. Should only be accessed on
   // target thread
   nsString mScriptFile;
   uint32_t mScriptLine;
   uint32_t mScriptColumn;
   uint64_t mInnerWindowID;
 
 private:
+
+  // Pointer to the target thread for checking whether we are
+  // on the target thread. This is intentionally a non-owning
+  // pointer in order not to affect the thread destruction
+  // sequence. This pointer must only be compared for equality
+  // and must not be dereferenced.
+  nsIThread* mTargetThread;
+
   // prevent bad usage
   EventSourceImpl(const EventSourceImpl& x) = delete;
   EventSourceImpl& operator=(const EventSourceImpl& x) = delete;
   ~EventSourceImpl()
   {
     if (IsClosed()) {
       return;
     }
@@ -343,16 +351,17 @@ EventSourceImpl::EventSourceImpl(EventSo
   , mMutex("EventSourceImpl::mMutex")
   , mFrozen(false)
   , mGoingToDispatchAllMessages(false)
   , mIsMainThread(NS_IsMainThread())
   , mIsShutDown(false)
   , mScriptLine(0)
   , mScriptColumn(0)
   , mInnerWindowID(0)
+  , mTargetThread(NS_GetCurrentThread())
 {
   MOZ_ASSERT(mEventSource);
   if (!mIsMainThread) {
     mEventSource->mIsMainThread = false;
   }
   SetReadyState(CONNECTING);
 }