Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 8; -*- */ |
michael@0 | 2 | /* vim: set sw=2 sts=2 ts=8 et tw=80 : */ |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | #include "TaskThrottler.h" |
michael@0 | 8 | |
michael@0 | 9 | namespace mozilla { |
michael@0 | 10 | namespace layers { |
michael@0 | 11 | |
michael@0 | 12 | TaskThrottler::TaskThrottler(const TimeStamp& aTimeStamp) |
michael@0 | 13 | : mOutstanding(false) |
michael@0 | 14 | , mQueuedTask(nullptr) |
michael@0 | 15 | , mStartTime(aTimeStamp) |
michael@0 | 16 | , mMean(1) |
michael@0 | 17 | { } |
michael@0 | 18 | |
michael@0 | 19 | void |
michael@0 | 20 | TaskThrottler::PostTask(const tracked_objects::Location& aLocation, |
michael@0 | 21 | CancelableTask* aTask, const TimeStamp& aTimeStamp) |
michael@0 | 22 | { |
michael@0 | 23 | aTask->SetBirthPlace(aLocation); |
michael@0 | 24 | |
michael@0 | 25 | if (mOutstanding) { |
michael@0 | 26 | if (mQueuedTask) { |
michael@0 | 27 | mQueuedTask->Cancel(); |
michael@0 | 28 | } |
michael@0 | 29 | mQueuedTask = aTask; |
michael@0 | 30 | } else { |
michael@0 | 31 | mStartTime = aTimeStamp; |
michael@0 | 32 | aTask->Run(); |
michael@0 | 33 | delete aTask; |
michael@0 | 34 | mOutstanding = true; |
michael@0 | 35 | } |
michael@0 | 36 | } |
michael@0 | 37 | |
michael@0 | 38 | void |
michael@0 | 39 | TaskThrottler::TaskComplete(const TimeStamp& aTimeStamp) |
michael@0 | 40 | { |
michael@0 | 41 | if (!mOutstanding) { |
michael@0 | 42 | return; |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | mMean.insert(aTimeStamp - mStartTime); |
michael@0 | 46 | |
michael@0 | 47 | if (mQueuedTask) { |
michael@0 | 48 | mStartTime = aTimeStamp; |
michael@0 | 49 | mQueuedTask->Run(); |
michael@0 | 50 | mQueuedTask = nullptr; |
michael@0 | 51 | } else { |
michael@0 | 52 | mOutstanding = false; |
michael@0 | 53 | } |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | TimeDuration |
michael@0 | 57 | TaskThrottler::TimeSinceLastRequest(const TimeStamp& aTimeStamp) |
michael@0 | 58 | { |
michael@0 | 59 | return aTimeStamp - mStartTime; |
michael@0 | 60 | } |
michael@0 | 61 | |
michael@0 | 62 | } |
michael@0 | 63 | } |