Beispiel #1
0
void
TaskThrottler::PostTask(const tracked_objects::Location& aLocation,
                        UniquePtr<CancelableTask> aTask, const TimeStamp& aTimeStamp)
{
  MonitorAutoLock lock(mMonitor);

  TASK_LOG("%p got a task posted; mOutstanding=%d\n", this, mOutstanding);
  aTask->SetBirthPlace(aLocation);

  if (mOutstanding) {
    CancelPendingTask(lock);
    if (TimeSinceLastRequest(aTimeStamp, lock) < mMaxWait) {
      mQueuedTask = Move(aTask);
      TASK_LOG("%p queued task %p\n", this, mQueuedTask.get());
      // Make sure the queued task is sent after mMaxWait time elapses,
      // even if we don't get a TaskComplete() until then.
      TimeDuration timeout = mMaxWait - TimeSinceLastRequest(aTimeStamp, lock);
      mTimeoutTask = NewRunnableMethod(this, &TaskThrottler::OnTimeout);
      APZThreadUtils::RunDelayedTaskOnCurrentThread(mTimeoutTask, timeout);
      return;
    }
    // we've been waiting for more than the max-wait limit, so just fall through
    // and send the new task already.
  }

  mStartTime = aTimeStamp;
  aTask->Run();
  mOutstanding = true;
}
Beispiel #2
0
void
TaskThrottler::PostTask(const tracked_objects::Location& aLocation,
                        UniquePtr<CancelableTask> aTask, const TimeStamp& aTimeStamp)
{
  aTask->SetBirthPlace(aLocation);

  if (mOutstanding) {
    if (mQueuedTask) {
      mQueuedTask->Cancel();
      mQueuedTask = nullptr;
    }
    if (TimeSinceLastRequest(aTimeStamp) < mMaxWait) {
      mQueuedTask = Move(aTask);
      return;
    }
    // we've been waiting for more than the max-wait limit, so just fall through
    // and send the new task already.
  }

  mStartTime = aTimeStamp;
  aTask->Run();
  mOutstanding = true;
}
Beispiel #3
0
TimeDuration
TaskThrottler::TimeSinceLastRequest(const TimeStamp& aTimeStamp)
{
  MonitorAutoLock lock(mMonitor);
  return TimeSinceLastRequest(aTimeStamp, lock);
}