Commit 2d079037 authored by Etienne Pierre-doray's avatar Etienne Pierre-doray Committed by Commit Bot

[TaskScheduler]: Cleanup Task.

This CL removes redundant members in base::internal::Task:
- delay: Redundant with PendingTask::delayed_run_time
- sequenced_time: Redundant with PendingTask::queue_time (unused when sequenced_time is used).

This clean up makes Task easier to read, and slightly more lightweight.

Change-Id: I7ed16bd3458d61f98d717f2f3dd83124f9f0121f
Reviewed-on: https://chromium-review.googlesource.com/c/1448977Reviewed-by: default avatarFrançois Doray <fdoray@chromium.org>
Reviewed-by: default avatarGabriel Charette <gab@chromium.org>
Commit-Queue: François Doray <fdoray@chromium.org>
Cr-Commit-Position: refs/heads/master@{#629969}
parent 963ba814
...@@ -46,8 +46,12 @@ struct BASE_EXPORT PendingTask { ...@@ -46,8 +46,12 @@ struct BASE_EXPORT PendingTask {
// The time when the task should be run. // The time when the task should be run.
base::TimeTicks delayed_run_time; base::TimeTicks delayed_run_time;
// The time at which the task was queued. Only set if the task was posted to // The time at which the task was queued. For SequenceManager tasks and
// the SequenceManager with SetAddQueueTimeToTasks(true). // TaskScheduler non-delayed tasks, this happens at post time. For
// TaskScheduler delayed tasks, this happens some time after the task's delay
// has expired. This is not set for SequenceManager tasks if
// SetAddQueueTimeToTasks(true) wasn't call. This defaults to a null TimeTicks
// if the task hasn't been inserted in a sequence yet.
TimeTicks queue_time; TimeTicks queue_time;
// Chain of up-to-four symbols of the parent tasks which led to this one being // Chain of up-to-four symbols of the parent tasks which led to this one being
......
...@@ -47,8 +47,8 @@ bool Sequence::Transaction::PushTask(Task task) { ...@@ -47,8 +47,8 @@ bool Sequence::Transaction::PushTask(Task task) {
// Use CHECK instead of DCHECK to crash earlier. See http://crbug.com/711167 // Use CHECK instead of DCHECK to crash earlier. See http://crbug.com/711167
// for details. // for details.
CHECK(task.task); CHECK(task.task);
DCHECK(task.sequenced_time.is_null()); DCHECK(task.queue_time.is_null());
task.sequenced_time = base::TimeTicks::Now(); task.queue_time = base::TimeTicks::Now();
task.task = sequence_->traits_.shutdown_behavior() == task.task = sequence_->traits_.shutdown_behavior() ==
TaskShutdownBehavior::BLOCK_SHUTDOWN TaskShutdownBehavior::BLOCK_SHUTDOWN
...@@ -79,11 +79,9 @@ SequenceSortKey Sequence::Transaction::GetSortKey() const { ...@@ -79,11 +79,9 @@ SequenceSortKey Sequence::Transaction::GetSortKey() const {
DCHECK(!IsEmpty()); DCHECK(!IsEmpty());
// Save the sequenced time of the next task in the sequence. // Save the sequenced time of the next task in the sequence.
base::TimeTicks next_task_sequenced_time = base::TimeTicks next_task_queue_time = sequence_->queue_.front().queue_time;
sequence_->queue_.front().sequenced_time;
return SequenceSortKey(sequence_->traits_.priority(), return SequenceSortKey(sequence_->traits_.priority(), next_task_queue_time);
next_task_sequenced_time);
} }
bool Sequence::Transaction::IsEmpty() const { bool Sequence::Transaction::IsEmpty() const {
......
...@@ -61,19 +61,19 @@ TEST(TaskSchedulerSequenceTest, PushTakeRemove) { ...@@ -61,19 +61,19 @@ TEST(TaskSchedulerSequenceTest, PushTakeRemove) {
// Take the task in front of the sequence. It should be task A. // Take the task in front of the sequence. It should be task A.
Optional<Task> task = sequence_transaction.TakeTask(); Optional<Task> task = sequence_transaction.TakeTask();
ExpectMockTask(&mock_task_a, &task.value()); ExpectMockTask(&mock_task_a, &task.value());
EXPECT_FALSE(task->sequenced_time.is_null()); EXPECT_FALSE(task->queue_time.is_null());
// Remove the empty slot. Task B should now be in front. // Remove the empty slot. Task B should now be in front.
EXPECT_FALSE(sequence_transaction.Pop()); EXPECT_FALSE(sequence_transaction.Pop());
task = sequence_transaction.TakeTask(); task = sequence_transaction.TakeTask();
ExpectMockTask(&mock_task_b, &task.value()); ExpectMockTask(&mock_task_b, &task.value());
EXPECT_FALSE(task->sequenced_time.is_null()); EXPECT_FALSE(task->queue_time.is_null());
// Remove the empty slot. Task C should now be in front. // Remove the empty slot. Task C should now be in front.
EXPECT_FALSE(sequence_transaction.Pop()); EXPECT_FALSE(sequence_transaction.Pop());
task = sequence_transaction.TakeTask(); task = sequence_transaction.TakeTask();
ExpectMockTask(&mock_task_c, &task.value()); ExpectMockTask(&mock_task_c, &task.value());
EXPECT_FALSE(task->sequenced_time.is_null()); EXPECT_FALSE(task->queue_time.is_null());
// Remove the empty slot. // Remove the empty slot.
EXPECT_FALSE(sequence_transaction.Pop()); EXPECT_FALSE(sequence_transaction.Pop());
...@@ -84,13 +84,13 @@ TEST(TaskSchedulerSequenceTest, PushTakeRemove) { ...@@ -84,13 +84,13 @@ TEST(TaskSchedulerSequenceTest, PushTakeRemove) {
// Task D should be in front. // Task D should be in front.
task = sequence_transaction.TakeTask(); task = sequence_transaction.TakeTask();
ExpectMockTask(&mock_task_d, &task.value()); ExpectMockTask(&mock_task_d, &task.value());
EXPECT_FALSE(task->sequenced_time.is_null()); EXPECT_FALSE(task->queue_time.is_null());
// Remove the empty slot. Task E should now be in front. // Remove the empty slot. Task E should now be in front.
EXPECT_FALSE(sequence_transaction.Pop()); EXPECT_FALSE(sequence_transaction.Pop());
task = sequence_transaction.TakeTask(); task = sequence_transaction.TakeTask();
ExpectMockTask(&mock_task_e, &task.value()); ExpectMockTask(&mock_task_e, &task.value());
EXPECT_FALSE(task->sequenced_time.is_null()); EXPECT_FALSE(task->queue_time.is_null());
// Remove the empty slot. The sequence should now be empty. // Remove the empty slot. The sequence should now be empty.
EXPECT_TRUE(sequence_transaction.Pop()); EXPECT_TRUE(sequence_transaction.Pop());
...@@ -116,7 +116,7 @@ TEST(TaskSchedulerSequenceTest, GetSortKeyBestEffort) { ...@@ -116,7 +116,7 @@ TEST(TaskSchedulerSequenceTest, GetSortKeyBestEffort) {
// Verify the sort key. // Verify the sort key.
EXPECT_EQ(TaskPriority::BEST_EFFORT, best_effort_sort_key.priority()); EXPECT_EQ(TaskPriority::BEST_EFFORT, best_effort_sort_key.priority());
EXPECT_EQ(take_best_effort_task->sequenced_time, EXPECT_EQ(take_best_effort_task->queue_time,
best_effort_sort_key.next_task_sequenced_time()); best_effort_sort_key.next_task_sequenced_time());
// Pop for correctness. // Pop for correctness.
...@@ -144,7 +144,7 @@ TEST(TaskSchedulerSequenceTest, GetSortKeyForeground) { ...@@ -144,7 +144,7 @@ TEST(TaskSchedulerSequenceTest, GetSortKeyForeground) {
// Verify the sort key. // Verify the sort key.
EXPECT_EQ(TaskPriority::USER_VISIBLE, foreground_sort_key.priority()); EXPECT_EQ(TaskPriority::USER_VISIBLE, foreground_sort_key.priority());
EXPECT_EQ(take_foreground_task->sequenced_time, EXPECT_EQ(take_foreground_task->queue_time,
foreground_sort_key.next_task_sequenced_time()); foreground_sort_key.next_task_sequenced_time());
// Pop for correctness. // Pop for correctness.
......
...@@ -23,8 +23,7 @@ Task::Task(const Location& posted_from, OnceClosure task, TimeDelta delay) ...@@ -23,8 +23,7 @@ Task::Task(const Location& posted_from, OnceClosure task, TimeDelta delay)
: PendingTask(posted_from, : PendingTask(posted_from,
std::move(task), std::move(task),
delay.is_zero() ? TimeTicks() : TimeTicks::Now() + delay, delay.is_zero() ? TimeTicks() : TimeTicks::Now() + delay,
Nestable::kNonNestable), Nestable::kNonNestable) {
delay(delay) {
// TaskScheduler doesn't use |sequence_num| but tracing (toplevel.flow) relies // TaskScheduler doesn't use |sequence_num| but tracing (toplevel.flow) relies
// on it being unique. While this subtle dependency is a bit overreaching, // on it being unique. While this subtle dependency is a bit overreaching,
// TaskScheduler is the only task system that doesn't use |sequence_num| and // TaskScheduler is the only task system that doesn't use |sequence_num| and
...@@ -38,8 +37,6 @@ Task::Task(const Location& posted_from, OnceClosure task, TimeDelta delay) ...@@ -38,8 +37,6 @@ Task::Task(const Location& posted_from, OnceClosure task, TimeDelta delay)
// this case. // this case.
Task::Task(Task&& other) noexcept Task::Task(Task&& other) noexcept
: PendingTask(std::move(other)), : PendingTask(std::move(other)),
delay(other.delay),
sequenced_time(other.sequenced_time),
sequenced_task_runner_ref(std::move(other.sequenced_task_runner_ref)), sequenced_task_runner_ref(std::move(other.sequenced_task_runner_ref)),
single_thread_task_runner_ref( single_thread_task_runner_ref(
std::move(other.single_thread_task_runner_ref)) {} std::move(other.single_thread_task_runner_ref)) {}
......
...@@ -37,15 +37,6 @@ struct BASE_EXPORT Task : public PendingTask { ...@@ -37,15 +37,6 @@ struct BASE_EXPORT Task : public PendingTask {
Task& operator=(Task&& other); Task& operator=(Task&& other);
// The delay that must expire before the task runs.
TimeDelta delay;
// The time at which the task was inserted in its sequence. For an undelayed
// task, this happens at post time. For a delayed task, this happens some
// time after the task's delay has expired. If the task hasn't been inserted
// in a sequence yet, this defaults to a null TimeTicks.
TimeTicks sequenced_time;
// A reference to the SequencedTaskRunner or SingleThreadTaskRunner that // A reference to the SequencedTaskRunner or SingleThreadTaskRunner that
// posted this task, if any. Used to set ThreadTaskRunnerHandle and/or // posted this task, if any. Used to set ThreadTaskRunnerHandle and/or
// SequencedTaskRunnerHandle while the task is running. // SequencedTaskRunnerHandle while the task is running.
......
...@@ -436,8 +436,8 @@ bool TaskTracker::WillPostTask(Task* task, ...@@ -436,8 +436,8 @@ bool TaskTracker::WillPostTask(Task* task,
DCHECK(task); DCHECK(task);
DCHECK(task->task); DCHECK(task->task);
if (!BeforePostTask(GetEffectiveShutdownBehavior(shutdown_behavior, if (!BeforePostTask(GetEffectiveShutdownBehavior(
!task->delay.is_zero()))) shutdown_behavior, !task->delayed_run_time.is_null())))
return false; return false;
if (task->delayed_run_time.is_null()) if (task->delayed_run_time.is_null())
...@@ -498,7 +498,7 @@ scoped_refptr<Sequence> TaskTracker::RunAndPopNextTask( ...@@ -498,7 +498,7 @@ scoped_refptr<Sequence> TaskTracker::RunAndPopNextTask(
const TaskShutdownBehavior effective_shutdown_behavior = const TaskShutdownBehavior effective_shutdown_behavior =
GetEffectiveShutdownBehavior(sequence->shutdown_behavior(), GetEffectiveShutdownBehavior(sequence->shutdown_behavior(),
!task->delay.is_zero()); !task->delayed_run_time.is_null());
const bool can_run_task = BeforeRunTask(effective_shutdown_behavior); const bool can_run_task = BeforeRunTask(effective_shutdown_behavior);
...@@ -588,7 +588,7 @@ void TaskTracker::RunOrSkipTask(Task task, ...@@ -588,7 +588,7 @@ void TaskTracker::RunOrSkipTask(Task task,
bool can_run_task) { bool can_run_task) {
DCHECK(sequence); DCHECK(sequence);
RecordLatencyHistogram(LatencyHistogramType::TASK_LATENCY, traits, RecordLatencyHistogram(LatencyHistogramType::TASK_LATENCY, traits,
task.sequenced_time); task.queue_time);
const bool previous_singleton_allowed = const bool previous_singleton_allowed =
ThreadRestrictions::SetSingletonAllowed( ThreadRestrictions::SetSingletonAllowed(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment