OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/scheduler/child/prioritizing_task_queue_selector.h" | 5 #include "components/scheduler/child/prioritizing_task_queue_selector.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/pending_task.h" | 8 #include "base/pending_task.h" |
9 #include "base/trace_event/trace_event_argument.h" | 9 #include "base/trace_event/trace_event_argument.h" |
10 | 10 |
11 namespace scheduler { | 11 namespace scheduler { |
12 | 12 |
13 PrioritizingTaskQueueSelector::PrioritizingTaskQueueSelector() | 13 PrioritizingTaskQueueSelector::PrioritizingTaskQueueSelector() |
14 : starvation_count_(0), task_queue_selector_observer_(nullptr) { | 14 : starvation_count_(0), task_queue_selector_observer_(nullptr), |
| 15 pre_shutdown_(false) { |
15 } | 16 } |
16 | 17 |
17 PrioritizingTaskQueueSelector::~PrioritizingTaskQueueSelector() { | 18 PrioritizingTaskQueueSelector::~PrioritizingTaskQueueSelector() { |
18 } | 19 } |
19 | 20 |
| 21 void PrioritizingTaskQueueSelector::PreShutdown() { |
| 22 pre_shutdown_ = true; |
| 23 } |
| 24 |
20 void PrioritizingTaskQueueSelector::RegisterWorkQueues( | 25 void PrioritizingTaskQueueSelector::RegisterWorkQueues( |
21 const std::vector<const base::TaskQueue*>& work_queues) { | 26 const std::vector<const base::TaskQueue*>& work_queues) { |
22 DCHECK(main_thread_checker_.CalledOnValidThread()); | 27 DCHECK(main_thread_checker_.CalledOnValidThread()); |
23 work_queues_ = work_queues; | 28 work_queues_ = work_queues; |
24 for (auto& queue_priority : queue_priorities_) { | 29 for (auto& queue_priority : queue_priorities_) { |
25 queue_priority.clear(); | 30 queue_priority.clear(); |
26 } | 31 } |
27 | 32 |
28 // By default, all work queues are set to normal priority. | 33 // By default, all work queues are set to normal priority. |
29 for (size_t i = 0; i < work_queues.size(); i++) { | 34 for (size_t i = 0; i < work_queues.size(); i++) { |
30 queue_priorities_[NORMAL_PRIORITY].insert(i); | 35 queue_priorities_[NORMAL_PRIORITY].insert(i); |
31 } | 36 } |
32 } | 37 } |
33 | 38 |
34 void PrioritizingTaskQueueSelector::SetQueuePriority(size_t queue_index, | 39 void PrioritizingTaskQueueSelector::SetQueuePriority(size_t queue_index, |
35 QueuePriority priority) { | 40 QueuePriority priority) { |
| 41 if (pre_shutdown_) |
| 42 return; |
36 DCHECK(main_thread_checker_.CalledOnValidThread()); | 43 DCHECK(main_thread_checker_.CalledOnValidThread()); |
37 DCHECK_LT(queue_index, work_queues_.size()); | 44 DCHECK_LT(queue_index, work_queues_.size()); |
38 DCHECK_LT(priority, QUEUE_PRIORITY_COUNT); | 45 DCHECK_LT(priority, QUEUE_PRIORITY_COUNT); |
39 bool previously_enabled = DisableQueueInternal(queue_index); | 46 bool previously_enabled = DisableQueueInternal(queue_index); |
40 queue_priorities_[priority].insert(queue_index); | 47 queue_priorities_[priority].insert(queue_index); |
41 if (task_queue_selector_observer_ && !previously_enabled) | 48 if (task_queue_selector_observer_ && !previously_enabled) |
42 task_queue_selector_observer_->OnTaskQueueEnabled(); | 49 task_queue_selector_observer_->OnTaskQueueEnabled(); |
43 } | 50 } |
44 | 51 |
45 void PrioritizingTaskQueueSelector::EnableQueue(size_t queue_index, | 52 void PrioritizingTaskQueueSelector::EnableQueue(size_t queue_index, |
46 QueuePriority priority) { | 53 QueuePriority priority) { |
| 54 if (pre_shutdown_) |
| 55 return; |
47 SetQueuePriority(queue_index, priority); | 56 SetQueuePriority(queue_index, priority); |
48 } | 57 } |
49 | 58 |
50 void PrioritizingTaskQueueSelector::DisableQueue(size_t queue_index) { | 59 void PrioritizingTaskQueueSelector::DisableQueue(size_t queue_index) { |
| 60 if (pre_shutdown_) |
| 61 return; |
51 DisableQueueInternal(queue_index); | 62 DisableQueueInternal(queue_index); |
52 } | 63 } |
53 | 64 |
54 bool PrioritizingTaskQueueSelector::DisableQueueInternal(size_t queue_index) { | 65 bool PrioritizingTaskQueueSelector::DisableQueueInternal(size_t queue_index) { |
55 DCHECK(main_thread_checker_.CalledOnValidThread()); | 66 DCHECK(main_thread_checker_.CalledOnValidThread()); |
56 DCHECK_LT(queue_index, work_queues_.size()); | 67 DCHECK_LT(queue_index, work_queues_.size()); |
57 bool previously_enabled = false; | 68 bool previously_enabled = false; |
58 for (auto& queue_priority : queue_priorities_) { | 69 for (auto& queue_priority : queue_priorities_) { |
59 if (queue_priority.erase(queue_index)) | 70 if (queue_priority.erase(queue_index)) |
60 previously_enabled = true; | 71 previously_enabled = true; |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 state->EndDictionary(); | 194 state->EndDictionary(); |
184 state->SetInteger("starvation_count", starvation_count_); | 195 state->SetInteger("starvation_count", starvation_count_); |
185 } | 196 } |
186 | 197 |
187 void PrioritizingTaskQueueSelector::SetTaskQueueSelectorObserver( | 198 void PrioritizingTaskQueueSelector::SetTaskQueueSelectorObserver( |
188 Observer* observer) { | 199 Observer* observer) { |
189 task_queue_selector_observer_ = observer; | 200 task_queue_selector_observer_ = observer; |
190 } | 201 } |
191 | 202 |
192 } // namespace scheduler | 203 } // namespace scheduler |
OLD | NEW |