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

Side by Side Diff: third_party/WebKit/Source/platform/scheduler/base/task_queue_manager.cc

Issue 2572893002: [Reland] Dont post delayed DoWork for disabled queues. (Closed)
Patch Set: Fix perftest Created 4 years 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "platform/scheduler/base/task_queue_manager.h" 5 #include "platform/scheduler/base/task_queue_manager.h"
6 6
7 #include <queue> 7 #include <queue>
8 #include <set> 8 #include <set>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 return; 211 return;
212 } 212 }
213 213
214 any_thread().immediate_do_work_posted_count++; 214 any_thread().immediate_do_work_posted_count++;
215 } 215 }
216 delegate_->PostTask(from_here, immediate_do_work_closure_); 216 delegate_->PostTask(from_here, immediate_do_work_closure_);
217 } 217 }
218 218
219 void TaskQueueManager::MaybeScheduleDelayedWork( 219 void TaskQueueManager::MaybeScheduleDelayedWork(
220 const tracked_objects::Location& from_here, 220 const tracked_objects::Location& from_here,
221 base::TimeTicks now, 221 LazyNow* lazy_now,
Sami 2016/12/14 16:29:38 Not something for this patch, but I'm feeling a li
alex clarke (OOO till 29th) 2016/12/14 16:50:36 Agreed it would be easy for that to happen. I'll
222 base::TimeDelta delay) { 222 base::TimeTicks run_time) {
223 DCHECK(main_thread_checker_.CalledOnValidThread()); 223 DCHECK(main_thread_checker_.CalledOnValidThread());
224 DCHECK_GE(delay, base::TimeDelta());
225 { 224 {
226 base::AutoLock lock(any_thread_lock_); 225 base::AutoLock lock(any_thread_lock_);
227 226
228 // Unless we're nested, don't post a delayed DoWork if there's an immediate 227 // Unless we're nested, don't post a delayed DoWork if there's an immediate
229 // DoWork in flight or we're inside a DoWork. We can rely on DoWork posting 228 // DoWork in flight or we're inside a DoWork. We can rely on DoWork posting
230 // a delayed continuation as needed. 229 // a delayed continuation as needed.
231 if (!any_thread().is_nested && 230 if (!any_thread().is_nested &&
232 (any_thread().immediate_do_work_posted_count > 0 || 231 (any_thread().immediate_do_work_posted_count > 0 ||
233 any_thread().do_work_running_count == 1)) { 232 any_thread().do_work_running_count == 1)) {
234 return; 233 return;
235 } 234 }
236 } 235 }
237 236
238 // De-duplicate DoWork posts. 237 // De-duplicate DoWork posts.
239 base::TimeTicks run_time = now + delay;
240 if (next_delayed_do_work_ <= run_time && !next_delayed_do_work_.is_null()) 238 if (next_delayed_do_work_ <= run_time && !next_delayed_do_work_.is_null())
241 return; 239 return;
242 240
241 cancelable_delayed_do_work_closure_.Reset(delayed_do_work_closure_);
242
243 base::TimeDelta delay =
244 std::max(base::TimeDelta(), run_time - lazy_now->Now());
245 next_delayed_do_work_ = lazy_now->Now() + delay;
246
243 TRACE_EVENT1(tracing_category_, "MaybeScheduleDelayedWorkInternal", 247 TRACE_EVENT1(tracing_category_, "MaybeScheduleDelayedWorkInternal",
244 "delay_ms", delay.InMillisecondsF()); 248 "delay_ms", delay.InMillisecondsF());
245 249
246 cancelable_delayed_do_work_closure_.Reset(delayed_do_work_closure_);
247 next_delayed_do_work_ = run_time;
248 delegate_->PostDelayedTask( 250 delegate_->PostDelayedTask(
249 from_here, cancelable_delayed_do_work_closure_.callback(), delay); 251 from_here, cancelable_delayed_do_work_closure_.callback(), delay);
250 } 252 }
251 253
254 void TaskQueueManager::CancelDelayedWork(base::TimeTicks run_time) {
255 DCHECK(main_thread_checker_.CalledOnValidThread());
256 if (next_delayed_do_work_ != run_time)
257 return;
258
259 cancelable_delayed_do_work_closure_.Cancel();
260 next_delayed_do_work_ = base::TimeTicks();
261 }
262
252 void TaskQueueManager::DoWork(bool delayed) { 263 void TaskQueueManager::DoWork(bool delayed) {
253 DCHECK(main_thread_checker_.CalledOnValidThread()); 264 DCHECK(main_thread_checker_.CalledOnValidThread());
254 TRACE_EVENT1("tracing_category_", "TaskQueueManager::DoWork", "delayed", 265 TRACE_EVENT1("tracing_category_", "TaskQueueManager::DoWork", "delayed",
255 delayed); 266 delayed);
256 LazyNow lazy_now(real_time_domain()->CreateLazyNow()); 267 LazyNow lazy_now(real_time_domain()->CreateLazyNow());
257 268
258 bool is_nested = delegate_->IsNested(); 269 bool is_nested = delegate_->IsNested();
259 if (!is_nested) 270 if (!is_nested)
260 queues_to_delete_.clear(); 271 queues_to_delete_.clear();
261 272
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
636 } 647 }
637 648
638 void TaskQueueManager::SetRecordTaskDelayHistograms( 649 void TaskQueueManager::SetRecordTaskDelayHistograms(
639 bool record_task_delay_histograms) { 650 bool record_task_delay_histograms) {
640 DCHECK(main_thread_checker_.CalledOnValidThread()); 651 DCHECK(main_thread_checker_.CalledOnValidThread());
641 record_task_delay_histograms_ = record_task_delay_histograms; 652 record_task_delay_histograms_ = record_task_delay_histograms;
642 } 653 }
643 654
644 } // namespace scheduler 655 } // namespace scheduler
645 } // namespace blink 656 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698