Rename GetIconID to GetIconId
[chromium-blink-merge.git] / components / scheduler / child / task_queue_sets.cc
blob3f7b0cf0a5a46fd7a03130ef9f726851565f010c
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "components/scheduler/child/task_queue_sets.h"
7 #include "base/logging.h"
8 #include "components/scheduler/child/task_queue_impl.h"
10 namespace scheduler {
11 namespace internal {
13 TaskQueueSets::TaskQueueSets(size_t num_sets)
14 : enqueue_order_to_queue_maps_(num_sets) {}
16 TaskQueueSets::~TaskQueueSets() {}
18 void TaskQueueSets::RemoveQueue(internal::TaskQueueImpl* queue) {
19 int enqueue_order;
20 bool has_enqueue_order =
21 queue->GetWorkQueueFrontTaskEnqueueOrder(&enqueue_order);
22 if (!has_enqueue_order)
23 return;
24 size_t set_index = queue->get_task_queue_set_index();
25 DCHECK_LT(set_index, enqueue_order_to_queue_maps_.size());
26 DCHECK_EQ(
27 queue,
28 enqueue_order_to_queue_maps_[set_index].find(enqueue_order)->second);
29 enqueue_order_to_queue_maps_[set_index].erase(enqueue_order);
32 void TaskQueueSets::AssignQueueToSet(internal::TaskQueueImpl* queue,
33 size_t set_index) {
34 DCHECK_LT(set_index, enqueue_order_to_queue_maps_.size());
35 int enqueue_order;
36 bool has_enqueue_order =
37 queue->GetWorkQueueFrontTaskEnqueueOrder(&enqueue_order);
38 size_t old_set = queue->get_task_queue_set_index();
39 DCHECK_LT(old_set, enqueue_order_to_queue_maps_.size());
40 queue->set_task_queue_set_index(set_index);
41 if (!has_enqueue_order)
42 return;
43 enqueue_order_to_queue_maps_[old_set].erase(enqueue_order);
44 enqueue_order_to_queue_maps_[set_index].insert(
45 std::make_pair(enqueue_order, queue));
48 void TaskQueueSets::OnPushQueue(internal::TaskQueueImpl* queue) {
49 int enqueue_order;
50 bool has_enqueue_order =
51 queue->GetWorkQueueFrontTaskEnqueueOrder(&enqueue_order);
52 DCHECK(has_enqueue_order);
53 size_t set_index = queue->get_task_queue_set_index();
54 DCHECK_LT(set_index, enqueue_order_to_queue_maps_.size()) << " set_index = "
55 << set_index;
56 enqueue_order_to_queue_maps_[set_index].insert(
57 std::make_pair(enqueue_order, queue));
60 void TaskQueueSets::OnPopQueue(internal::TaskQueueImpl* queue) {
61 size_t set_index = queue->get_task_queue_set_index();
62 DCHECK_LT(set_index, enqueue_order_to_queue_maps_.size());
63 DCHECK(!enqueue_order_to_queue_maps_[set_index].empty()) << " set_index = "
64 << set_index;
65 DCHECK_EQ(enqueue_order_to_queue_maps_[set_index].begin()->second, queue)
66 << " set_index = " << set_index;
67 // O(1) amortised.
68 enqueue_order_to_queue_maps_[set_index].erase(
69 enqueue_order_to_queue_maps_[set_index].begin());
70 int enqueue_order;
71 bool has_enqueue_order =
72 queue->GetWorkQueueFrontTaskEnqueueOrder(&enqueue_order);
73 if (!has_enqueue_order)
74 return;
75 enqueue_order_to_queue_maps_[set_index].insert(
76 std::make_pair(enqueue_order, queue));
79 bool TaskQueueSets::GetOldestQueueInSet(
80 size_t set_index,
81 internal::TaskQueueImpl** out_queue) const {
82 DCHECK_LT(set_index, enqueue_order_to_queue_maps_.size());
83 if (enqueue_order_to_queue_maps_[set_index].empty())
84 return false;
85 *out_queue = enqueue_order_to_queue_maps_[set_index].begin()->second;
86 return true;
89 bool TaskQueueSets::IsSetEmpty(size_t set_index) const {
90 DCHECK_LT(set_index, enqueue_order_to_queue_maps_.size())
91 << " set_index = " << set_index;
92 return enqueue_order_to_queue_maps_[set_index].empty();
95 } // namespace internal
96 } // namespace scheduler