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

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

Issue 2163753004: Rename CancellationFlag to AtomicFlag. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix dcheck death test Created 4 years, 4 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_scheduler_impl.h ('k') | chrome/browser/after_startup_task_utils.cc » ('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_scheduler_impl.h" 5 #include "base/task_scheduler/task_scheduler_impl.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 13 matching lines...) Expand all
24 const WorkerPoolIndexForTraitsCallback& 24 const WorkerPoolIndexForTraitsCallback&
25 worker_pool_index_for_traits_callback) { 25 worker_pool_index_for_traits_callback) {
26 std::unique_ptr<TaskSchedulerImpl> scheduler( 26 std::unique_ptr<TaskSchedulerImpl> scheduler(
27 new TaskSchedulerImpl(worker_pool_index_for_traits_callback)); 27 new TaskSchedulerImpl(worker_pool_index_for_traits_callback));
28 scheduler->Initialize(worker_pool_params_vector); 28 scheduler->Initialize(worker_pool_params_vector);
29 return scheduler; 29 return scheduler;
30 } 30 }
31 31
32 TaskSchedulerImpl::~TaskSchedulerImpl() { 32 TaskSchedulerImpl::~TaskSchedulerImpl() {
33 #if DCHECK_IS_ON() 33 #if DCHECK_IS_ON()
34 DCHECK(join_for_testing_returned_.IsSignaled()); 34 DCHECK(join_for_testing_returned_.IsSet());
35 #endif 35 #endif
36 } 36 }
37 37
38 void TaskSchedulerImpl::PostTaskWithTraits( 38 void TaskSchedulerImpl::PostTaskWithTraits(
39 const tracked_objects::Location& from_here, 39 const tracked_objects::Location& from_here,
40 const TaskTraits& traits, 40 const TaskTraits& traits,
41 const Closure& task) { 41 const Closure& task) {
42 // Post |task| as part of a one-off single-task Sequence. 42 // Post |task| as part of a one-off single-task Sequence.
43 GetWorkerPoolForTraits(traits)->PostTaskWithSequence( 43 GetWorkerPoolForTraits(traits)->PostTaskWithSequence(
44 WrapUnique(new Task(from_here, task, traits, TimeDelta())), 44 WrapUnique(new Task(from_here, task, traits, TimeDelta())),
45 make_scoped_refptr(new Sequence), nullptr); 45 make_scoped_refptr(new Sequence), nullptr);
46 } 46 }
47 47
48 scoped_refptr<TaskRunner> TaskSchedulerImpl::CreateTaskRunnerWithTraits( 48 scoped_refptr<TaskRunner> TaskSchedulerImpl::CreateTaskRunnerWithTraits(
49 const TaskTraits& traits, 49 const TaskTraits& traits,
50 ExecutionMode execution_mode) { 50 ExecutionMode execution_mode) {
51 return GetWorkerPoolForTraits(traits)->CreateTaskRunnerWithTraits( 51 return GetWorkerPoolForTraits(traits)->CreateTaskRunnerWithTraits(
52 traits, execution_mode); 52 traits, execution_mode);
53 } 53 }
54 54
55 void TaskSchedulerImpl::Shutdown() { 55 void TaskSchedulerImpl::Shutdown() {
56 // TODO(fdoray): Increase the priority of BACKGROUND tasks blocking shutdown. 56 // TODO(fdoray): Increase the priority of BACKGROUND tasks blocking shutdown.
57 task_tracker_.Shutdown(); 57 task_tracker_.Shutdown();
58 } 58 }
59 59
60 void TaskSchedulerImpl::JoinForTesting() { 60 void TaskSchedulerImpl::JoinForTesting() {
61 #if DCHECK_IS_ON() 61 #if DCHECK_IS_ON()
62 DCHECK(!join_for_testing_returned_.IsSignaled()); 62 DCHECK(!join_for_testing_returned_.IsSet());
63 #endif 63 #endif
64 for (const auto& worker_pool : worker_pools_) 64 for (const auto& worker_pool : worker_pools_)
65 worker_pool->JoinForTesting(); 65 worker_pool->JoinForTesting();
66 service_thread_->JoinForTesting(); 66 service_thread_->JoinForTesting();
67 #if DCHECK_IS_ON() 67 #if DCHECK_IS_ON()
68 join_for_testing_returned_.Signal(); 68 join_for_testing_returned_.Set();
69 #endif 69 #endif
70 } 70 }
71 71
72 TaskSchedulerImpl::TaskSchedulerImpl(const WorkerPoolIndexForTraitsCallback& 72 TaskSchedulerImpl::TaskSchedulerImpl(const WorkerPoolIndexForTraitsCallback&
73 worker_pool_index_for_traits_callback) 73 worker_pool_index_for_traits_callback)
74 : delayed_task_manager_( 74 : delayed_task_manager_(
75 Bind(&TaskSchedulerImpl::OnDelayedRunTimeUpdated, Unretained(this))), 75 Bind(&TaskSchedulerImpl::OnDelayedRunTimeUpdated, Unretained(this))),
76 worker_pool_index_for_traits_callback_( 76 worker_pool_index_for_traits_callback_(
77 worker_pool_index_for_traits_callback) 77 worker_pool_index_for_traits_callback)
78 #if DCHECK_IS_ON()
79 ,
80 join_for_testing_returned_(WaitableEvent::ResetPolicy::MANUAL,
81 WaitableEvent::InitialState::NOT_SIGNALED)
82 #endif
83 { 78 {
84 DCHECK(!worker_pool_index_for_traits_callback_.is_null()); 79 DCHECK(!worker_pool_index_for_traits_callback_.is_null());
85 } 80 }
86 81
87 void TaskSchedulerImpl::Initialize( 82 void TaskSchedulerImpl::Initialize(
88 const std::vector<SchedulerWorkerPoolParams>& worker_pool_params_vector) { 83 const std::vector<SchedulerWorkerPoolParams>& worker_pool_params_vector) {
89 DCHECK(!worker_pool_params_vector.empty()); 84 DCHECK(!worker_pool_params_vector.empty());
90 85
91 const SchedulerWorkerPoolImpl::ReEnqueueSequenceCallback 86 const SchedulerWorkerPoolImpl::ReEnqueueSequenceCallback
92 re_enqueue_sequence_callback = 87 re_enqueue_sequence_callback =
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 GetWorkerPoolForTraits(traits)->ReEnqueueSequence(std::move(sequence), 124 GetWorkerPoolForTraits(traits)->ReEnqueueSequence(std::move(sequence),
130 sort_key); 125 sort_key);
131 } 126 }
132 127
133 void TaskSchedulerImpl::OnDelayedRunTimeUpdated() { 128 void TaskSchedulerImpl::OnDelayedRunTimeUpdated() {
134 service_thread_->WakeUp(); 129 service_thread_->WakeUp();
135 } 130 }
136 131
137 } // namespace internal 132 } // namespace internal
138 } // namespace base 133 } // namespace base
OLDNEW
« no previous file with comments | « base/task_scheduler/task_scheduler_impl.h ('k') | chrome/browser/after_startup_task_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698