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

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

Issue 2258133002: [scheduler] Implement time-based cpu throttling. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Renamed Enable/Disable to Enable/DisableThrottling. Created 4 years, 3 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 1b0980a4f4e00ccf236f4bc2250683d0b744c3b7..ad779a23afa20eeae935a2acc1f12051f289904c 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
@@ -514,6 +514,8 @@ bool TaskQueueImpl::IsEmpty() const {
}
bool TaskQueueImpl::HasPendingImmediateWork() const {
+ LazyNow lazy_now = main_thread_only().time_domain->CreateLazyNow();
alex clarke (OOO till 29th) 2016/09/15 12:19:34 nit: revert this and change on line 529
altimin 2016/09/15 15:52:10 Done.
+
// Any work queue tasks count as immediate work.
if (!main_thread_only().delayed_work_queue->Empty() ||
!main_thread_only().immediate_work_queue->Empty()) {
@@ -524,7 +526,7 @@ bool TaskQueueImpl::HasPendingImmediateWork() const {
// immediate work.
if (!main_thread_only().delayed_incoming_queue.empty() &&
main_thread_only().delayed_incoming_queue.begin()->delayed_run_time <=
- main_thread_only().time_domain->CreateLazyNow().Now()) {
+ lazy_now.Now()) {
return true;
}
@@ -533,6 +535,13 @@ bool TaskQueueImpl::HasPendingImmediateWork() const {
return !any_thread().immediate_incoming_queue.empty();
}
+base::Optional<base::TimeTicks> TaskQueueImpl::GetNextScheduledWakeUp() {
+ if (main_thread_only().delayed_incoming_queue.empty())
+ return base::nullopt;
+
+ return main_thread_only().delayed_incoming_queue.begin()->delayed_run_time;
+}
+
void TaskQueueImpl::MoveReadyDelayedTasksToDelayedWorkQueue(LazyNow* lazy_now) {
// Enqueue all delayed tasks that should be running now.
while (!main_thread_only().delayed_incoming_queue.empty()) {
@@ -704,22 +713,27 @@ void TaskQueueImpl::NotifyDidProcessTask(
}
void TaskQueueImpl::SetTimeDomain(TimeDomain* time_domain) {
- base::AutoLock lock(any_thread_lock_);
- DCHECK(time_domain);
- // NOTE this is similar to checking |any_thread().task_queue_manager| but the
- // TaskQueueSelectorTests constructs TaskQueueImpl directly with a null
- // task_queue_manager. Instead we check |any_thread().time_domain| which is
- // another way of asserting that UnregisterTaskQueue has not been called.
- DCHECK(any_thread().time_domain);
- if (!any_thread().time_domain)
- return;
- DCHECK(main_thread_checker_.CalledOnValidThread());
- if (time_domain == main_thread_only().time_domain)
- return;
-
+ {
+ base::AutoLock lock(any_thread_lock_);
+ DCHECK(time_domain);
+ // NOTE this is similar to checking |any_thread().task_queue_manager| but
+ // the
alex clarke (OOO till 29th) 2016/09/15 12:19:34 reformat please.
altimin 2016/09/15 15:52:10 Done.
+ // TaskQueueSelectorTests constructs TaskQueueImpl directly with a null
+ // task_queue_manager. Instead we check |any_thread().time_domain| which is
+ // another way of asserting that UnregisterTaskQueue has not been called.
+ DCHECK(any_thread().time_domain);
+ if (!any_thread().time_domain)
+ return;
+ DCHECK(main_thread_checker_.CalledOnValidThread());
+ if (time_domain == main_thread_only().time_domain)
+ return;
+
+ any_thread().time_domain = time_domain;
+ }
+ // We rely here on TimeDomain::Register/UnregisterAsUpdatableTaskQueue being
Sami 2016/09/15 16:30:29 nit: really we're relying on TimeDomain::MigrateQu
altimin 2016/09/16 13:38:48 It's more tricky. TimeDomain::MigrateQueue is main
+ // thread-safe.
main_thread_only().time_domain->MigrateQueue(this, time_domain);
main_thread_only().time_domain = time_domain;
- any_thread().time_domain = time_domain;
}
TimeDomain* TaskQueueImpl::GetTimeDomain() const {

Powered by Google App Engine
This is Rietveld 408576698