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

Side by Side Diff: base/task_scheduler/task_tracker.cc

Issue 2857103005: Exempt the Service Thread from BLOCK_SHUTDOWN DCHECKs (Closed)
Patch Set: Created 3 years, 7 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "base/task_scheduler/task_tracker.h" 5 #include "base/task_scheduler/task_tracker.h"
6 6
7 #include <limits> 7 #include <limits>
8 #include <string> 8 #include <string>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/debug/task_annotator.h" 11 #include "base/debug/task_annotator.h"
12 #include "base/json/json_writer.h" 12 #include "base/json/json_writer.h"
13 #include "base/logging.h"
14 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
15 #include "base/metrics/histogram_macros.h" 14 #include "base/metrics/histogram_macros.h"
16 #include "base/sequence_token.h" 15 #include "base/sequence_token.h"
17 #include "base/synchronization/condition_variable.h" 16 #include "base/synchronization/condition_variable.h"
18 #include "base/task_scheduler/scoped_set_task_priority_for_current_thread.h" 17 #include "base/task_scheduler/scoped_set_task_priority_for_current_thread.h"
19 #include "base/threading/sequenced_task_runner_handle.h" 18 #include "base/threading/sequenced_task_runner_handle.h"
20 #include "base/threading/thread_restrictions.h" 19 #include "base/threading/thread_restrictions.h"
21 #include "base/threading/thread_task_runner_handle.h" 20 #include "base/threading/thread_task_runner_handle.h"
22 #include "base/time/time.h" 21 #include "base/time/time.h"
23 #include "base/trace_event/trace_event.h" 22 #include "base/trace_event/trace_event.h"
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 // posted during shutdown. Otherwise, the histogram has already been 371 // posted during shutdown. Otherwise, the histogram has already been
373 // recorded in BeforePostTask(). 372 // recorded in BeforePostTask().
374 if (num_block_shutdown_tasks_posted_during_shutdown_ < 373 if (num_block_shutdown_tasks_posted_during_shutdown_ <
375 kMaxBlockShutdownTasksPostedDuringShutdown) { 374 kMaxBlockShutdownTasksPostedDuringShutdown) {
376 RecordNumBlockShutdownTasksPostedDuringShutdown( 375 RecordNumBlockShutdownTasksPostedDuringShutdown(
377 num_block_shutdown_tasks_posted_during_shutdown_); 376 num_block_shutdown_tasks_posted_during_shutdown_);
378 } 377 }
379 } 378 }
380 } 379 }
381 380
381 #if DCHECK_IS_ON()
382 bool TaskTracker::IsExemptFromBlockingShutdownChecks() {
383 return false;
384 }
385 #endif
386
382 bool TaskTracker::BeforePostTask(TaskShutdownBehavior shutdown_behavior) { 387 bool TaskTracker::BeforePostTask(TaskShutdownBehavior shutdown_behavior) {
383 if (shutdown_behavior == TaskShutdownBehavior::BLOCK_SHUTDOWN) { 388 if (shutdown_behavior == TaskShutdownBehavior::BLOCK_SHUTDOWN) {
384 // BLOCK_SHUTDOWN tasks block shutdown between the moment they are posted 389 // BLOCK_SHUTDOWN tasks block shutdown between the moment they are posted
385 // and the moment they complete their execution. 390 // and the moment they complete their execution.
386 const bool shutdown_started = state_->IncrementNumTasksBlockingShutdown(); 391 const bool shutdown_started = state_->IncrementNumTasksBlockingShutdown();
387 392
388 if (shutdown_started) { 393 if (shutdown_started) {
389 AutoSchedulerLock auto_lock(shutdown_lock_); 394 AutoSchedulerLock auto_lock(shutdown_lock_);
390 395
391 // A BLOCK_SHUTDOWN task posted after shutdown has completed is an 396 // A BLOCK_SHUTDOWN task posted after shutdown has completed is an
392 // ordering bug. This aims to catch those early. 397 // ordering bug. This aims to catch those early.
393 DCHECK(shutdown_event_); 398 DCHECK(shutdown_event_);
394 DCHECK(!shutdown_event_->IsSignaled()); 399 if (shutdown_event_->IsSignaled()) {
400 // TODO(robliao): http://crbug.com/698140. Since the service thread
401 // doesn't stop processing its own tasks at shutdown, we may still
402 // attempt to post a BLOCK_SHUTDOWN task in response to a
403 // FileDescriptorWatcher. Delayed tasks are fine because they're marked
fdoray 2017/05/03 20:34:33 Delayed tasks go through TaskTracker::BeforePostTa
robliao 2017/05/03 21:11:17 Indeed. I was thinking of the general case. Remove
404 // as SKIP_ON_SHUTDOWN and are accounted for shutdown purposes.
405 DCHECK(IsExemptFromBlockingShutdownChecks());
406 state_->DecrementNumTasksBlockingShutdown();
407 return false;
408 }
395 409
396 ++num_block_shutdown_tasks_posted_during_shutdown_; 410 ++num_block_shutdown_tasks_posted_during_shutdown_;
397 411
398 if (num_block_shutdown_tasks_posted_during_shutdown_ == 412 if (num_block_shutdown_tasks_posted_during_shutdown_ ==
399 kMaxBlockShutdownTasksPostedDuringShutdown) { 413 kMaxBlockShutdownTasksPostedDuringShutdown) {
400 // Record the TaskScheduler.BlockShutdownTasksPostedDuringShutdown 414 // Record the TaskScheduler.BlockShutdownTasksPostedDuringShutdown
401 // histogram as soon as its upper bound is hit. That way, a value will 415 // histogram as soon as its upper bound is hit. That way, a value will
402 // be recorded even if an infinite number of BLOCK_SHUTDOWN tasks are 416 // be recorded even if an infinite number of BLOCK_SHUTDOWN tasks are
403 // posted, preventing shutdown to complete. 417 // posted, preventing shutdown to complete.
404 RecordNumBlockShutdownTasksPostedDuringShutdown( 418 RecordNumBlockShutdownTasksPostedDuringShutdown(
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 task_latency_histograms_[static_cast<int>(task->traits.priority())] 507 task_latency_histograms_[static_cast<int>(task->traits.priority())]
494 [task->traits.may_block() || 508 [task->traits.may_block() ||
495 task->traits.with_base_sync_primitives() 509 task->traits.with_base_sync_primitives()
496 ? 1 510 ? 1
497 : 0] 511 : 0]
498 ->AddTime(task_latency); 512 ->AddTime(task_latency);
499 } 513 }
500 514
501 } // namespace internal 515 } // namespace internal
502 } // namespace base 516 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698