Bug 1147555 - Invert the ordering of our priority queue. r=mattwoodrow, a=lizzard
authorBobby Holley <bobbyholley@gmail.com>
Mon, 30 Mar 2015 15:14:48 -0700
changeset 265337 c7b040ac1f4bfbca19a2058548f4270beaadb15f
parent 265336 010344056448cd2a1edc1cb94f9ba5c1972c0d36
child 265338 9a3865593e662e76a49e586f27a91f63f9428b92
push id4718
push userraliiev@mozilla.com
push dateMon, 11 May 2015 18:39:53 +0000
treeherdermozilla-beta@c20c4ef55f08 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmattwoodrow, lizzard
bugs1147555
milestone39.0a2
Bug 1147555 - Invert the ordering of our priority queue. r=mattwoodrow, a=lizzard
dom/media/MediaTimer.cpp
dom/media/MediaTimer.h
--- a/dom/media/MediaTimer.cpp
+++ b/dom/media/MediaTimer.cpp
@@ -106,17 +106,19 @@ MediaTimer::UpdateLocked()
   MOZ_ASSERT(OnMediaTimerThread());
   mMonitor.AssertCurrentThreadOwns();
   mUpdateScheduled = false;
 
   // Resolve all the promises whose time is up.
   TimeStamp now = TimeStamp::Now();
   while (!mEntries.empty() && mEntries.top().mTimeStamp <= now) {
     mEntries.top().mPromise->Resolve(true, __func__);
+    DebugOnly<TimeStamp> poppedTimeStamp = mEntries.top().mTimeStamp;
     mEntries.pop();
+    MOZ_ASSERT_IF(!mEntries.empty(), *&poppedTimeStamp <= mEntries.top().mTimeStamp);
   }
 
   // If we've got no more entries, cancel any pending timer and bail out.
   if (mEntries.empty()) {
     CancelTimerIfArmed();
     return;
   }
 
--- a/dom/media/MediaTimer.h
+++ b/dom/media/MediaTimer.h
@@ -73,19 +73,22 @@ private:
     TimeStamp mTimeStamp;
     nsRefPtr<MediaTimerPromise::Private> mPromise;
 
     explicit Entry(const TimeStamp& aTimeStamp, const char* aCallSite)
       : mTimeStamp(aTimeStamp)
       , mPromise(new MediaTimerPromise::Private(aCallSite))
     {}
 
+    // Define a < overload that reverses ordering because std::priority_queue
+    // provides access to the largest element, and we want the smallest
+    // (i.e. the soonest).
     bool operator<(const Entry& aOther) const
     {
-      return mTimeStamp < aOther.mTimeStamp;
+      return mTimeStamp > aOther.mTimeStamp;
     }
   };
 
   ThreadSafeAutoRefCnt mRefCnt;
   NS_DECL_OWNINGTHREAD
   nsCOMPtr<nsIEventTarget> mThread;
   std::priority_queue<Entry> mEntries;
   Monitor mMonitor;