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

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: self-review 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..cef742ea1cc4c0da4b266ab450cd3c2f1d925de0 100644
--- a/base/task_scheduler/scheduler_worker.cc
+++ b/base/task_scheduler/scheduler_worker.cc
@@ -39,6 +39,13 @@ class SchedulerWorker::Thread : public PlatformThread::Delegate {
while (!outer_->task_tracker_->IsShutdownComplete() &&
!outer_->ShouldExitForTesting()) {
DCHECK(outer_);
+
+ const ThreadPriority desired_thread_priority = GetDesiredThreadPriority();
+ if (desired_thread_priority != actual_thread_priority_) {
+ PlatformThread::SetCurrentThreadPriority(desired_thread_priority);
+ actual_thread_priority_ = desired_thread_priority;
+ }
+
// Get the sequence containing the next task to execute.
scoped_refptr<Sequence> sequence = outer_->delegate_->GetWork(outer_);
if (!sequence) {
@@ -91,17 +98,17 @@ class SchedulerWorker::Thread : public PlatformThread::Delegate {
private:
Thread(SchedulerWorker* outer)
- : outer_(outer),
- wake_up_event_(WaitableEvent::ResetPolicy::MANUAL,
- WaitableEvent::InitialState::NOT_SIGNALED) {
+ : outer_(outer),
+ wake_up_event_(WaitableEvent::ResetPolicy::MANUAL,
+ WaitableEvent::InitialState::NOT_SIGNALED),
+ actual_thread_priority_(GetDesiredThreadPriority()) {
DCHECK(outer_);
}
void Initialize() {
constexpr size_t kDefaultStackSize = 0;
- PlatformThread::CreateWithPriority(kDefaultStackSize, this,
- &thread_handle_,
- outer_->thread_priority_);
+ PlatformThread::CreateWithPriority(kDefaultStackSize, this, &thread_handle_,
+ actual_thread_priority_);
}
void WaitForWork() {
@@ -117,6 +124,19 @@ class SchedulerWorker::Thread : public PlatformThread::Delegate {
wake_up_event_.Reset();
}
+ // Returns the desired thread priority based on the worker priority and the
+ // current shutdown state.
+ ThreadPriority GetDesiredThreadPriority() {
+ DCHECK(outer_);
+
+ if (outer_->task_tracker_->HasShutdownStarted() &&
+ static_cast<int>(outer_->thread_priority_) <
+ static_cast<int>(ThreadPriority::NORMAL)) {
+ return ThreadPriority::NORMAL;
+ }
+ return outer_->thread_priority_;
+ }
+
PlatformThreadHandle thread_handle_;
SchedulerWorker* outer_;
@@ -124,6 +144,10 @@ class SchedulerWorker::Thread : public PlatformThread::Delegate {
// Event signaled to wake up this thread.
WaitableEvent wake_up_event_;
+ // Actual priority of this thread. May be different from
+ // |outer_->thread_priority_| during shutdown.
+ ThreadPriority actual_thread_priority_;
robliao 2016/07/20 22:31:48 Use current_thread_priority since that's what it's
fdoray 2016/07/21 13:21:56 Done.
+
DISALLOW_COPY_AND_ASSIGN(Thread);
};
« 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