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) { |