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"
13 TaskQueueSets::TaskQueueSets(size_t num_sets
) : age_to_queue_maps_(num_sets
) {}
15 TaskQueueSets::~TaskQueueSets() {}
17 void TaskQueueSets::RemoveQueue(internal::TaskQueueImpl
* queue
) {
19 bool has_age
= queue
->GetWorkQueueFrontTaskAge(&age
);
22 size_t set_index
= queue
->get_task_queue_set_index();
23 DCHECK_LT(set_index
, age_to_queue_maps_
.size());
24 age_to_queue_maps_
[set_index
].erase(age
);
27 void TaskQueueSets::AssignQueueToSet(internal::TaskQueueImpl
* queue
,
29 DCHECK_LT(set_index
, age_to_queue_maps_
.size());
31 bool has_age
= queue
->GetWorkQueueFrontTaskAge(&age
);
32 size_t old_set
= queue
->get_task_queue_set_index();
33 DCHECK_LT(old_set
, age_to_queue_maps_
.size());
34 queue
->set_task_queue_set_index(set_index
);
37 age_to_queue_maps_
[old_set
].erase(age
);
38 age_to_queue_maps_
[set_index
].insert(std::make_pair(age
, queue
));
41 void TaskQueueSets::OnPushQueue(internal::TaskQueueImpl
* queue
) {
43 bool has_age
= queue
->GetWorkQueueFrontTaskAge(&age
);
45 size_t set_index
= queue
->get_task_queue_set_index();
46 DCHECK_LT(set_index
, age_to_queue_maps_
.size()) << " set_index = "
48 age_to_queue_maps_
[set_index
].insert(std::make_pair(age
, queue
));
51 void TaskQueueSets::OnPopQueue(internal::TaskQueueImpl
* queue
) {
52 size_t set_index
= queue
->get_task_queue_set_index();
53 DCHECK_LT(set_index
, age_to_queue_maps_
.size());
54 DCHECK(!age_to_queue_maps_
[set_index
].empty()) << " set_index = "
56 DCHECK_EQ(age_to_queue_maps_
[set_index
].begin()->second
, queue
)
57 << " set_index = " << set_index
;
59 age_to_queue_maps_
[set_index
].erase(age_to_queue_maps_
[set_index
].begin());
61 bool has_age
= queue
->GetWorkQueueFrontTaskAge(&age
);
64 age_to_queue_maps_
[set_index
].insert(std::make_pair(age
, queue
));
67 bool TaskQueueSets::GetOldestQueueInSet(
69 internal::TaskQueueImpl
** out_queue
) const {
70 DCHECK_LT(set_index
, age_to_queue_maps_
.size());
71 if (age_to_queue_maps_
[set_index
].empty())
73 *out_queue
= age_to_queue_maps_
[set_index
].begin()->second
;
77 } // namespace internal
78 } // namespace scheduler