OLD | NEW |
---|---|
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/scheduler_worker.h" | 5 #include "base/task_scheduler/scheduler_worker.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 10 matching lines...) Expand all Loading... | |
21 static std::unique_ptr<Thread> Create(SchedulerWorker* outer) { | 21 static std::unique_ptr<Thread> Create(SchedulerWorker* outer) { |
22 std::unique_ptr<Thread> thread(new Thread(outer)); | 22 std::unique_ptr<Thread> thread(new Thread(outer)); |
23 thread->Initialize(); | 23 thread->Initialize(); |
24 if (thread->thread_handle_.is_null()) | 24 if (thread->thread_handle_.is_null()) |
25 return nullptr; | 25 return nullptr; |
26 return thread; | 26 return thread; |
27 } | 27 } |
28 | 28 |
29 // PlatformThread::Delegate. | 29 // PlatformThread::Delegate. |
30 void ThreadMain() override { | 30 void ThreadMain() override { |
31 // True once the thread's priority has been bumped to accelerate shutdown. | |
32 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.
| |
33 | |
31 // Set if this thread was detached. | 34 // Set if this thread was detached. |
32 std::unique_ptr<Thread> detached_thread; | 35 std::unique_ptr<Thread> detached_thread; |
33 | 36 |
34 outer_->delegate_->OnMainEntry(outer_); | 37 outer_->delegate_->OnMainEntry(outer_); |
35 | 38 |
36 // A SchedulerWorker starts out waiting for work. | 39 // A SchedulerWorker starts out waiting for work. |
37 WaitForWork(); | 40 WaitForWork(); |
38 | 41 |
39 while (!outer_->task_tracker_->IsShutdownComplete() && | 42 while (!outer_->task_tracker_->IsShutdownComplete() && |
40 !outer_->ShouldExitForTesting()) { | 43 !outer_->ShouldExitForTesting()) { |
41 DCHECK(outer_); | 44 DCHECK(outer_); |
45 | |
46 // Bump the thread's priority during shutdown. | |
47 if (outer_->thread_priority_ == ThreadPriority::BACKGROUND && | |
48 !thread_priority_bumped_for_shutdown && | |
49 outer_->task_tracker_->IsShutdownInProgress()) { | |
50 PlatformThread::SetCurrentThreadPriority(ThreadPriority::NORMAL); | |
51 thread_priority_bumped_for_shutdown = true; | |
52 } | |
53 | |
42 // Get the sequence containing the next task to execute. | 54 // Get the sequence containing the next task to execute. |
43 scoped_refptr<Sequence> sequence = outer_->delegate_->GetWork(outer_); | 55 scoped_refptr<Sequence> sequence = outer_->delegate_->GetWork(outer_); |
44 if (!sequence) { | 56 if (!sequence) { |
45 if (outer_->delegate_->CanDetach(outer_)) { | 57 if (outer_->delegate_->CanDetach(outer_)) { |
46 detached_thread = outer_->Detach(); | 58 detached_thread = outer_->Detach(); |
47 if (detached_thread) { | 59 if (detached_thread) { |
48 DCHECK_EQ(detached_thread.get(), this); | 60 DCHECK_EQ(detached_thread.get(), this); |
49 PlatformThread::Detach(thread_handle_); | 61 PlatformThread::Detach(thread_handle_); |
50 outer_ = nullptr; | 62 outer_ = nullptr; |
51 break; | 63 break; |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
213 CreateThread(); | 225 CreateThread(); |
214 } | 226 } |
215 | 227 |
216 bool SchedulerWorker::ShouldExitForTesting() const { | 228 bool SchedulerWorker::ShouldExitForTesting() const { |
217 AutoSchedulerLock auto_lock(should_exit_for_testing_lock_); | 229 AutoSchedulerLock auto_lock(should_exit_for_testing_lock_); |
218 return should_exit_for_testing_; | 230 return should_exit_for_testing_; |
219 } | 231 } |
220 | 232 |
221 } // namespace internal | 233 } // namespace internal |
222 } // namespace base | 234 } // namespace base |
OLD | NEW |