Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(477)

Unified Diff: third_party/WebKit/Source/platform/scheduler/base/task_queue_impl.cc

Issue 2786083005: scheduler: Maintain a constant enqueue order for every task (Closed)
Patch Set: WASM workaround no longer needed Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/platform/scheduler/base/task_queue_impl.cc
diff --git a/third_party/WebKit/Source/platform/scheduler/base/task_queue_impl.cc b/third_party/WebKit/Source/platform/scheduler/base/task_queue_impl.cc
index c1545520ab9df637cbba40596e322fb09a910f6a..0645793d5f12345a8aae17e39dcef349068cc6b4 100644
--- a/third_party/WebKit/Source/platform/scheduler/base/task_queue_impl.cc
+++ b/third_party/WebKit/Source/platform/scheduler/base/task_queue_impl.cc
@@ -109,39 +109,22 @@ TaskQueueImpl::Task::Task()
: PendingTask(tracked_objects::Location(),
base::Closure(),
base::TimeTicks(),
- true),
-#ifndef NDEBUG
- enqueue_order_set_(false),
-#endif
- enqueue_order_(0) {
+ true) {
sequence_num = 0;
}
TaskQueueImpl::Task::Task(const tracked_objects::Location& posted_from,
base::OnceClosure task,
- base::TimeTicks desired_run_time,
- EnqueueOrder sequence_number,
+ EnqueueOrder enqueue_order,
bool nestable)
- : PendingTask(posted_from, std::move(task), desired_run_time, nestable),
-#ifndef NDEBUG
- enqueue_order_set_(false),
-#endif
- enqueue_order_(0) {
- sequence_num = sequence_number;
-}
-
-TaskQueueImpl::Task::Task(const tracked_objects::Location& posted_from,
- base::OnceClosure task,
- base::TimeTicks desired_run_time,
- EnqueueOrder sequence_number,
- bool nestable,
- EnqueueOrder enqueue_order)
- : PendingTask(posted_from, std::move(task), desired_run_time, nestable),
-#ifndef NDEBUG
- enqueue_order_set_(true),
-#endif
+ : PendingTask(posted_from,
+ std::move(task),
+ enqueue_order.delayed_run_time,
+ nestable),
enqueue_order_(enqueue_order) {
- sequence_num = sequence_number;
+ // Note: these properties are only used for tracing.
+ sequence_num = static_cast<int>(enqueue_order.sequence_num);
+ delayed_run_time = enqueue_order.delayed_run_time;
}
TaskQueueImpl::AnyThread::AnyThread(TaskQueueManager* task_queue_manager,
@@ -230,11 +213,11 @@ bool TaskQueueImpl::PostImmediateTaskImpl(
if (!any_thread().task_queue_manager)
return false;
- EnqueueOrder sequence_number =
- any_thread().task_queue_manager->GetNextSequenceNumber();
+ EnqueueOrder enqueue_order =
+ any_thread().task_queue_manager->GetNextEnqueueOrder(base::TimeTicks());
PushOntoImmediateIncomingQueueLocked(from_here, std::move(task),
- base::TimeTicks(), sequence_number,
+ enqueue_order,
task_type != TaskType::NON_NESTABLE);
return true;
}
@@ -253,14 +236,14 @@ bool TaskQueueImpl::PostDelayedTaskImpl(
if (!main_thread_only().task_queue_manager)
return false;
- EnqueueOrder sequence_number =
- main_thread_only().task_queue_manager->GetNextSequenceNumber();
-
base::TimeTicks time_domain_now = main_thread_only().time_domain->Now();
base::TimeTicks time_domain_delayed_run_time = time_domain_now + delay;
+ EnqueueOrder enqueue_order =
+ main_thread_only().task_queue_manager->GetNextEnqueueOrder(
+ time_domain_delayed_run_time);
PushOntoDelayedIncomingQueueFromMainThread(
- Task(from_here, std::move(task), time_domain_delayed_run_time,
- sequence_number, task_type != TaskType::NON_NESTABLE),
+ Task(from_here, std::move(task), enqueue_order,
+ task_type != TaskType::NON_NESTABLE),
time_domain_now);
} else {
// NOTE posting a delayed task from a different thread is not expected to
@@ -271,14 +254,14 @@ bool TaskQueueImpl::PostDelayedTaskImpl(
if (!any_thread().task_queue_manager)
return false;
- EnqueueOrder sequence_number =
- any_thread().task_queue_manager->GetNextSequenceNumber();
-
base::TimeTicks time_domain_now = any_thread().time_domain->Now();
base::TimeTicks time_domain_delayed_run_time = time_domain_now + delay;
+ EnqueueOrder enqueue_order =
+ any_thread().task_queue_manager->GetNextEnqueueOrder(
+ time_domain_delayed_run_time);
PushOntoDelayedIncomingQueueLocked(
- Task(from_here, std::move(task), time_domain_delayed_run_time,
- sequence_number, task_type != TaskType::NON_NESTABLE));
+ Task(from_here, std::move(task), enqueue_order,
+ task_type != TaskType::NON_NESTABLE));
}
return true;
}
@@ -306,15 +289,13 @@ void TaskQueueImpl::PushOntoDelayedIncomingQueueFromMainThread(
void TaskQueueImpl::PushOntoDelayedIncomingQueueLocked(Task pending_task) {
any_thread().task_queue_manager->DidQueueTask(pending_task);
- int thread_hop_task_sequence_number =
- any_thread().task_queue_manager->GetNextSequenceNumber();
+ EnqueueOrder thread_hop_task_enqueue_order =
+ any_thread().task_queue_manager->GetNextEnqueueOrder(base::TimeTicks());
PushOntoImmediateIncomingQueueLocked(
- FROM_HERE,
- base::Bind(&TaskQueueImpl::ScheduleDelayedWorkTask, this,
- base::Passed(&pending_task)),
- base::TimeTicks(),
- thread_hop_task_sequence_number,
- false);
+ FROM_HERE,
+ base::Bind(&TaskQueueImpl::ScheduleDelayedWorkTask, this,
+ base::Passed(&pending_task)),
+ thread_hop_task_enqueue_order, false);
}
void TaskQueueImpl::ScheduleDelayedWorkTask(Task pending_task) {
@@ -341,8 +322,7 @@ void TaskQueueImpl::ScheduleDelayedWorkTask(Task pending_task) {
void TaskQueueImpl::PushOntoImmediateIncomingQueueLocked(
const tracked_objects::Location& posted_from,
base::OnceClosure task,
- base::TimeTicks desired_run_time,
- EnqueueOrder sequence_number,
+ EnqueueOrder enqueue_order,
bool nestable) {
// If the |immediate_incoming_queue| is empty we need a DoWork posted to make
// it run.
@@ -352,8 +332,7 @@ void TaskQueueImpl::PushOntoImmediateIncomingQueueLocked(
base::AutoLock lock(immediate_incoming_queue_lock_);
was_immediate_incoming_queue_empty = immediate_incoming_queue().empty();
immediate_incoming_queue().emplace_back(posted_from, std::move(task),
- desired_run_time, sequence_number,
- nestable, sequence_number);
+ enqueue_order, nestable);
any_thread().task_queue_manager->DidQueueTask(
immediate_incoming_queue().back());
}
@@ -365,9 +344,10 @@ void TaskQueueImpl::PushOntoImmediateIncomingQueueLocked(
RunsTasksOnCurrentThread() &&
(!IsQueueEnabled() || main_thread_only().current_fence);
any_thread().task_queue_manager->OnQueueHasIncomingImmediateWork(
- this, sequence_number, queue_is_blocked);
+ this, enqueue_order, queue_is_blocked);
if (any_thread().observer)
- any_thread().observer->OnQueueNextWakeUpChanged(this, desired_run_time);
+ any_thread().observer->OnQueueNextWakeUpChanged(
+ this, enqueue_order.delayed_run_time);
}
TraceQueueSize();
@@ -450,8 +430,6 @@ TaskQueueImpl::WakeUpForDelayedWork(LazyNow* lazy_now) {
}
if (task.delayed_run_time > lazy_now->Now())
break;
- task.set_enqueue_order(
- main_thread_only().task_queue_manager->GetNextSequenceNumber());
main_thread_only().delayed_work_queue->Push(std::move(task));
main_thread_only().delayed_incoming_queue.pop();
}
@@ -625,11 +603,14 @@ void TaskQueueImpl::InsertFence(TaskQueue::InsertFencePosition position) {
if (!main_thread_only().task_queue_manager)
return;
- EnqueueOrder previous_fence = main_thread_only().current_fence;
+ SequenceNumber previous_fence = main_thread_only().current_fence;
main_thread_only().current_fence =
position == TaskQueue::InsertFencePosition::NOW
- ? main_thread_only().task_queue_manager->GetNextSequenceNumber()
- : static_cast<EnqueueOrder>(EnqueueOrderValues::BLOCKING_FENCE);
+ ? main_thread_only()
+ .task_queue_manager->GetNextEnqueueOrder(base::TimeTicks())
+ .sequence_num
+ : static_cast<SequenceNumber>(
+ EnqueueOrderSequenceNumberValues::BLOCKING_FENCE);
// Tasks posted after this point will have a strictly higher enqueue order
// and will be blocked from running.
@@ -642,8 +623,9 @@ void TaskQueueImpl::InsertFence(TaskQueue::InsertFencePosition position) {
previous_fence < main_thread_only().current_fence) {
base::AutoLock lock(immediate_incoming_queue_lock_);
if (!immediate_incoming_queue().empty() &&
- immediate_incoming_queue().front().enqueue_order() > previous_fence &&
- immediate_incoming_queue().front().enqueue_order() <
+ immediate_incoming_queue().front().enqueue_order().sequence_num >
+ previous_fence &&
+ immediate_incoming_queue().front().enqueue_order().sequence_num <
main_thread_only().current_fence) {
task_unblocked = true;
}
@@ -659,7 +641,7 @@ void TaskQueueImpl::RemoveFence() {
if (!main_thread_only().task_queue_manager)
return;
- EnqueueOrder previous_fence = main_thread_only().current_fence;
+ SequenceNumber previous_fence = main_thread_only().current_fence;
main_thread_only().current_fence = 0;
bool task_unblocked = main_thread_only().immediate_work_queue->RemoveFence();
@@ -668,7 +650,8 @@ void TaskQueueImpl::RemoveFence() {
if (!task_unblocked && previous_fence) {
base::AutoLock lock(immediate_incoming_queue_lock_);
if (!immediate_incoming_queue().empty() &&
- immediate_incoming_queue().front().enqueue_order() > previous_fence) {
+ immediate_incoming_queue().front().enqueue_order().sequence_num >
+ previous_fence) {
task_unblocked = true;
}
}
@@ -692,7 +675,7 @@ bool TaskQueueImpl::BlockedByFence() const {
if (immediate_incoming_queue().empty())
return true;
- return immediate_incoming_queue().front().enqueue_order() >
+ return immediate_incoming_queue().front().enqueue_order().sequence_num >
main_thread_only().current_fence;
}
@@ -703,10 +686,10 @@ bool TaskQueueImpl::CouldTaskRun(EnqueueOrder enqueue_order) const {
if (!main_thread_only().current_fence)
return true;
- return enqueue_order < main_thread_only().current_fence;
+ return enqueue_order.sequence_num < main_thread_only().current_fence;
}
-EnqueueOrder TaskQueueImpl::GetFenceForTest() const {
+SequenceNumber TaskQueueImpl::GetFenceForTest() const {
return main_thread_only().current_fence;
}
@@ -739,12 +722,10 @@ void TaskQueueImpl::TaskAsValueInto(const Task& task,
base::trace_event::TracedValue* state) {
state->BeginDictionary();
state->SetString("posted_from", task.posted_from.ToString());
-#ifndef NDEBUG
- if (task.enqueue_order_set())
- state->SetInteger("enqueue_order", task.enqueue_order());
-#else
- state->SetInteger("enqueue_order", task.enqueue_order());
-#endif
+ state->SetInteger("enqueue_order.delayed_run_time",
+ task.enqueue_order().delayed_run_time.ToInternalValue());
+ state->SetInteger("enqueue_order.sequence_num",
+ task.enqueue_order().sequence_num);
state->SetInteger("sequence_num", task.sequence_num);
state->SetBoolean("nestable", task.nestable);
state->SetBoolean("is_high_res", task.is_high_res);

Powered by Google App Engine
This is Rietveld 408576698