Bug 1553567: Use MaxValue to initialize/reset nsThread::mCurrentEventLoopDepth, not -1. r=froydnj
authorJim Blandy <jimb@mozilla.com>
Thu, 23 May 2019 10:22:57 +0000
changeset 475198 44b529f579ea09f0955fdc16b34999350860f526
parent 475197 3304277f5bde56d355b81d3caa62673f4545b0e3
child 475199 409b2e43be0e312669b5662940f500401806d2cf
push id36057
push useraciure@mozilla.com
push dateThu, 23 May 2019 21:52:03 +0000
treeherdermozilla-central@d551d37b9ad0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1553567
milestone69.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 1553567: Use MaxValue to initialize/reset nsThread::mCurrentEventLoopDepth, not -1. r=froydnj Since the purpose of mCurrentEventLoopDepth is to be ordered in comparison with mNestedEventLoopDepth, it's a bit deceptive to give it a value that would appear to be less than any reasonable depth but is, because the variables in question are unsigned, actually greater than any reasonable depth. Using mozilla::MaxValue<uint32_t>::value is clearer. Differential Revision: https://phabricator.services.mozilla.com/D32198
xpcom/threads/nsThread.cpp
--- a/xpcom/threads/nsThread.cpp
+++ b/xpcom/threads/nsThread.cpp
@@ -21,16 +21,17 @@
 #include "nsAutoPtr.h"
 #include "nsCOMPtr.h"
 #include "nsQueryObject.h"
 #include "pratom.h"
 #include "mozilla/BackgroundHangMonitor.h"
 #include "mozilla/CycleCollectedJSContext.h"
 #include "mozilla/Logging.h"
 #include "nsIObserverService.h"
+#include "mozilla/IntegerTypeTraits.h"
 #include "mozilla/IOInterposer.h"
 #include "mozilla/ipc/MessageChannel.h"
 #include "mozilla/ipc/BackgroundChild.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/SchedulerGroup.h"
 #include "mozilla/Services.h"
 #include "mozilla/StaticPrefs.h"
 #include "mozilla/SystemGroup.h"
@@ -587,17 +588,17 @@ nsThread::nsThread(NotNull<SynchronizedE
     : mEvents(aQueue.get()),
       mEventTarget(
           new ThreadEventTarget(mEvents.get(), aMainThread == MAIN_THREAD)),
       mShutdownContext(nullptr),
       mScriptObserver(nullptr),
       mThread(nullptr),
       mStackSize(aStackSize),
       mNestedEventLoopDepth(0),
-      mCurrentEventLoopDepth(-1),
+      mCurrentEventLoopDepth(MaxValue<uint32_t>::value),
       mShutdownRequired(false),
       mPriority(PRIORITY_NORMAL),
       mIsMainThread(uint8_t(aMainThread)),
       mCanInvokeJS(false),
       mCurrentEvent(nullptr),
       mCurrentEventStart(TimeStamp::Now()),
       mCurrentPerformanceCounter(nullptr) {
   mLastLongTaskEnd = mCurrentEventStart;
@@ -607,17 +608,17 @@ nsThread::nsThread(NotNull<SynchronizedE
 nsThread::nsThread()
     : mEvents(nullptr),
       mEventTarget(nullptr),
       mShutdownContext(nullptr),
       mScriptObserver(nullptr),
       mThread(nullptr),
       mStackSize(0),
       mNestedEventLoopDepth(0),
-      mCurrentEventLoopDepth(-1),
+      mCurrentEventLoopDepth(MaxValue<uint32_t>::value),
       mShutdownRequired(false),
       mPriority(PRIORITY_NORMAL),
       mIsMainThread(NOT_MAIN_THREAD),
       mCanInvokeJS(false),
       mCurrentEvent(nullptr),
       mCurrentEventStart(TimeStamp::Now()),
       mCurrentPerformanceCounter(nullptr) {
   mLastLongTaskEnd = mCurrentEventStart;
@@ -1207,17 +1208,17 @@ nsThread::ProcessNextEvent(bool aMayWait
         // We're done with this dispatch
         if (currentPerformanceCounter) {
           mozilla::TimeDuration duration =
               TimeStamp::Now() - mCurrentEventStart;
           currentPerformanceCounter->IncrementExecutionDuration(
               duration.ToMicroseconds());
         }
         mCurrentEvent = nullptr;
-        mCurrentEventLoopDepth = -1;
+        mCurrentEventLoopDepth = MaxValue<uint32_t>::value;
         mCurrentPerformanceCounter = nullptr;
       }
     } else if (aMayWait) {
       MOZ_ASSERT(ShuttingDown(), "This should only happen when shutting down");
       rv = NS_ERROR_UNEXPECTED;
     }
   }