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

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

Issue 2161213002: TaskScheduler: Bump thread priority during shutdown. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: CR gab #26 (Set* -> Update* and disable on Linux) Created 4 years, 5 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_unittest.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_tracker.h" 5 #include "base/task_scheduler/task_tracker.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "base/atomicops.h" 9 #include "base/atomicops.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 TaskTracker::TaskTracker() : state_(new State) {} 117 TaskTracker::TaskTracker() : state_(new State) {}
118 TaskTracker::~TaskTracker() = default; 118 TaskTracker::~TaskTracker() = default;
119 119
120 void TaskTracker::Shutdown() { 120 void TaskTracker::Shutdown() {
121 { 121 {
122 AutoSchedulerLock auto_lock(shutdown_lock_); 122 AutoSchedulerLock auto_lock(shutdown_lock_);
123 123
124 // This method can only be called once. 124 // This method can only be called once.
125 DCHECK(!shutdown_event_); 125 DCHECK(!shutdown_event_);
126 DCHECK(!num_block_shutdown_tasks_posted_during_shutdown_); 126 DCHECK(!num_block_shutdown_tasks_posted_during_shutdown_);
127 DCHECK(!state_->HasShutdownStarted());
127 128
128 shutdown_event_.reset( 129 shutdown_event_.reset(
129 new WaitableEvent(WaitableEvent::ResetPolicy::MANUAL, 130 new WaitableEvent(WaitableEvent::ResetPolicy::MANUAL,
130 WaitableEvent::InitialState::NOT_SIGNALED)); 131 WaitableEvent::InitialState::NOT_SIGNALED));
131 132
132 const bool tasks_are_blocking_shutdown = state_->StartShutdown(); 133 const bool tasks_are_blocking_shutdown = state_->StartShutdown();
133 134
134 // From now, if a thread causes the number of tasks blocking shutdown to 135 // From now, if a thread causes the number of tasks blocking shutdown to
135 // become zero, it will call OnBlockingShutdownTasksComplete(). 136 // become zero, it will call OnBlockingShutdownTasksComplete().
136 137
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 208
208 TRACE_TASK_EXECUTION(kRunFunctionName, *task); 209 TRACE_TASK_EXECUTION(kRunFunctionName, *task);
209 210
210 debug::TaskAnnotator task_annotator; 211 debug::TaskAnnotator task_annotator;
211 task_annotator.RunTask(kQueueFunctionName, *task); 212 task_annotator.RunTask(kQueueFunctionName, *task);
212 } 213 }
213 214
214 AfterRunTask(shutdown_behavior); 215 AfterRunTask(shutdown_behavior);
215 } 216 }
216 217
218 bool TaskTracker::HasShutdownStarted() const {
219 return state_->HasShutdownStarted();
220 }
221
217 bool TaskTracker::IsShutdownComplete() const { 222 bool TaskTracker::IsShutdownComplete() const {
218 AutoSchedulerLock auto_lock(shutdown_lock_); 223 AutoSchedulerLock auto_lock(shutdown_lock_);
219 return shutdown_event_ && shutdown_event_->IsSignaled(); 224 return shutdown_event_ && shutdown_event_->IsSignaled();
220 } 225 }
221 226
222 bool TaskTracker::IsShuttingDownForTesting() const { 227 void TaskTracker::SetHasShutdownStartedForTesting() {
223 AutoSchedulerLock auto_lock(shutdown_lock_); 228 state_->StartShutdown();
224 return shutdown_event_ && !shutdown_event_->IsSignaled();
225 } 229 }
226 230
227 bool TaskTracker::BeforePostTask(TaskShutdownBehavior shutdown_behavior) { 231 bool TaskTracker::BeforePostTask(TaskShutdownBehavior shutdown_behavior) {
228 if (shutdown_behavior == TaskShutdownBehavior::BLOCK_SHUTDOWN) { 232 if (shutdown_behavior == TaskShutdownBehavior::BLOCK_SHUTDOWN) {
229 // BLOCK_SHUTDOWN tasks block shutdown between the moment they are posted 233 // BLOCK_SHUTDOWN tasks block shutdown between the moment they are posted
230 // and the moment they complete their execution. 234 // and the moment they complete their execution.
231 const bool shutdown_started = state_->IncrementNumTasksBlockingShutdown(); 235 const bool shutdown_started = state_->IncrementNumTasksBlockingShutdown();
232 236
233 if (shutdown_started) { 237 if (shutdown_started) {
234 AutoSchedulerLock auto_lock(shutdown_lock_); 238 AutoSchedulerLock auto_lock(shutdown_lock_);
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 322
319 // This method can only be called after shutdown has started. 323 // This method can only be called after shutdown has started.
320 DCHECK(state_->HasShutdownStarted()); 324 DCHECK(state_->HasShutdownStarted());
321 DCHECK(shutdown_event_); 325 DCHECK(shutdown_event_);
322 326
323 shutdown_event_->Signal(); 327 shutdown_event_->Signal();
324 } 328 }
325 329
326 } // namespace internal 330 } // namespace internal
327 } // namespace base 331 } // namespace base
OLDNEW
« no previous file with comments | « base/task_scheduler/task_tracker.h ('k') | base/task_scheduler/task_tracker_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698