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

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

Issue 2857103005: Exempt the Service Thread from BLOCK_SHUTDOWN DCHECKs (Closed)
Patch Set: CR Feedback 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
« no previous file with comments | « base/task_scheduler/task_tracker.h ('k') | base/task_scheduler/task_tracker_posix.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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::IsPostingBlockShutdownTaskAfterShutdownAllowed() {
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.
404 #if DCHECK_IS_ON()
405 DCHECK(IsPostingBlockShutdownTaskAfterShutdownAllowed());
406 #endif
407 state_->DecrementNumTasksBlockingShutdown();
408 return false;
409 }
395 410
396 ++num_block_shutdown_tasks_posted_during_shutdown_; 411 ++num_block_shutdown_tasks_posted_during_shutdown_;
397 412
398 if (num_block_shutdown_tasks_posted_during_shutdown_ == 413 if (num_block_shutdown_tasks_posted_during_shutdown_ ==
399 kMaxBlockShutdownTasksPostedDuringShutdown) { 414 kMaxBlockShutdownTasksPostedDuringShutdown) {
400 // Record the TaskScheduler.BlockShutdownTasksPostedDuringShutdown 415 // Record the TaskScheduler.BlockShutdownTasksPostedDuringShutdown
401 // histogram as soon as its upper bound is hit. That way, a value will 416 // 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 417 // be recorded even if an infinite number of BLOCK_SHUTDOWN tasks are
403 // posted, preventing shutdown to complete. 418 // posted, preventing shutdown to complete.
404 RecordNumBlockShutdownTasksPostedDuringShutdown( 419 RecordNumBlockShutdownTasksPostedDuringShutdown(
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 task_latency_histograms_[static_cast<int>(task->traits.priority())] 508 task_latency_histograms_[static_cast<int>(task->traits.priority())]
494 [task->traits.may_block() || 509 [task->traits.may_block() ||
495 task->traits.with_base_sync_primitives() 510 task->traits.with_base_sync_primitives()
496 ? 1 511 ? 1
497 : 0] 512 : 0]
498 ->AddTime(task_latency); 513 ->AddTime(task_latency);
499 } 514 }
500 515
501 } // namespace internal 516 } // namespace internal
502 } // namespace base 517 } // namespace base
OLDNEW
« no previous file with comments | « base/task_scheduler/task_tracker.h ('k') | base/task_scheduler/task_tracker_posix.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698