[ThreadPool]: Unify PendingTask::queue_time
This CL sets PendingTask::queue_time in (ThreadPool) Sequence
at post time, to match SequenceManager.
This allows us to retrieve delay of delayed tasks, which is used in
follow-up
https://chromium-review.googlesource.com/c/chromium/src/+/2824468
and later on in timer slack implementation.
This also means ThreadPool priority queue now uses
GetDesiredExecutionTime (similar to SequenceManager) that's either
queue_time or delayed_run_time.
Change-Id: I7322f32ed06db2bb9fc424f752954891438f84ae
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2835985
Reviewed-by: Erik Chen <[email protected]>
Reviewed-by: Gabriel Charette <[email protected]>
Commit-Queue: Etienne Pierre-Doray <[email protected]>
Cr-Commit-Position: refs/heads/master@{#876745}
diff --git a/base/pending_task.h b/base/pending_task.h
index dc68e26..b40c334 100644
--- a/base/pending_task.h
+++ b/base/pending_task.h
@@ -24,9 +24,11 @@
// for use by classes that queue and execute tasks.
struct BASE_EXPORT PendingTask {
PendingTask();
+ PendingTask(const Location& posted_from, OnceClosure task);
PendingTask(const Location& posted_from,
OnceClosure task,
- TimeTicks delayed_run_time = TimeTicks(),
+ TimeTicks queue_time,
+ TimeTicks delayed_run_time,
Nestable nestable = Nestable::kNestable);
PendingTask(PendingTask&& other);
~PendingTask();
@@ -36,25 +38,27 @@
// Used to support sorting.
bool operator<(const PendingTask& other) const;
+ // Returns the time at which this task should run. This is |delayed_run_time|
+ // for a delayed task, |queue_time| otherwise.
+ base::TimeTicks GetDesiredExecutionTime() const;
+
// The task to run.
OnceClosure task;
// The site this PendingTask was posted from.
Location posted_from;
+ // The time at which the task was queued, which happens at post time. For
+ // deferred non-nestable tasks, this is reset when the nested loop exits and
+ // the deferred tasks are pushed back at the front of the queue. This is not
+ // set for immediate SequenceManager tasks unless SetAddQueueTimeToTasks(true)
+ // was called. This defaults to a null TimeTicks if the task hasn't been
+ // inserted in a sequence yet.
+ TimeTicks queue_time;
+
// The time when the task should be run. This is null for an immediate task.
base::TimeTicks delayed_run_time;
- // The time at which the task was queued. For SequenceManager tasks and
- // ThreadPool non-delayed tasks, this happens at post time. For ThreadPool
- // delayed tasks, this happens some time after the task's delay has expired.
- // For deferred non-nestable tasks, this is reset when the nested loop exits
- // and the deferred tasks are pushed back at the front of the queue. This is
- // not set for SequenceManager tasks if SetAddQueueTimeToTasks(true) wasn't
- // called. This defaults to a null TimeTicks if the task hasn't been inserted
- // in a sequence yet.
- TimeTicks queue_time;
-
// Chain of symbols of the parent tasks which led to this one being posted.
static constexpr size_t kTaskBacktraceLength = 4;
std::array<const void*, kTaskBacktraceLength> task_backtrace = {};