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

Unified Diff: base/task_scheduler/scheduler_worker.cc

Issue 2161213002: TaskScheduler: Bump thread priority during shutdown. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 side-by-side diff with in-line comments
Download patch
Index: base/task_scheduler/scheduler_worker.cc
diff --git a/base/task_scheduler/scheduler_worker.cc b/base/task_scheduler/scheduler_worker.cc
index 5a2a7d6a92b96272e1d148edeaec2c4a1782b672..cc1e68d63f5e98001cdb68496edc567fa7a3e341 100644
--- a/base/task_scheduler/scheduler_worker.cc
+++ b/base/task_scheduler/scheduler_worker.cc
@@ -28,6 +28,9 @@ class SchedulerWorker::Thread : public PlatformThread::Delegate {
// PlatformThread::Delegate.
void ThreadMain() override {
+ // True once the thread's priority has been bumped to accelerate shutdown.
+ bool thread_priority_bumped_for_shutdown = false;
robliao 2016/07/19 22:41:28 I wonder if it might be more extensible to keep tr
fdoray 2016/07/20 18:22:21 I like the idea of keeping track of |thread_priori
robliao 2016/07/20 19:14:57 If GetCurrentThreadPriority is nearly as fast as r
gab 2016/07/20 20:30:09 I much prefer a local variable to a call to the OS
fdoray 2016/07/20 20:30:37 GetCurrentThreadPriority() is fast but not sure th
robliao 2016/07/20 22:31:48 This state is already stored in the TEB, so I'd ra
fdoray 2016/07/21 13:21:56 Let me know if I understood your comment correctly
robliao 2016/07/21 17:05:51 Yup! Thanks.
+
// Set if this thread was detached.
std::unique_ptr<Thread> detached_thread;
@@ -39,6 +42,15 @@ class SchedulerWorker::Thread : public PlatformThread::Delegate {
while (!outer_->task_tracker_->IsShutdownComplete() &&
!outer_->ShouldExitForTesting()) {
DCHECK(outer_);
+
+ // Bump the thread's priority during shutdown.
+ if (outer_->thread_priority_ == ThreadPriority::BACKGROUND &&
+ !thread_priority_bumped_for_shutdown &&
+ outer_->task_tracker_->IsShutdownInProgress()) {
+ PlatformThread::SetCurrentThreadPriority(ThreadPriority::NORMAL);
+ thread_priority_bumped_for_shutdown = true;
+ }
+
// Get the sequence containing the next task to execute.
scoped_refptr<Sequence> sequence = outer_->delegate_->GetWork(outer_);
if (!sequence) {
« no previous file with comments | « no previous file | base/task_scheduler/scheduler_worker_unittest.cc » ('j') | base/task_scheduler/scheduler_worker_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698