| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #ifndef COMPONENTS_SCHEDULER_BASE_WORK_QUEUE_SETS_H_ | |
| 6 #define COMPONENTS_SCHEDULER_BASE_WORK_QUEUE_SETS_H_ | |
| 7 | |
| 8 #include <stddef.h> | |
| 9 | |
| 10 #include <map> | |
| 11 #include <vector> | |
| 12 | |
| 13 #include "base/logging.h" | |
| 14 #include "base/macros.h" | |
| 15 #include "base/trace_event/trace_event_argument.h" | |
| 16 #include "components/scheduler/base/task_queue_impl.h" | |
| 17 #include "components/scheduler/scheduler_export.h" | |
| 18 | |
| 19 namespace scheduler { | |
| 20 namespace internal { | |
| 21 class TaskQueueImpl; | |
| 22 | |
| 23 class SCHEDULER_EXPORT WorkQueueSets { | |
| 24 public: | |
| 25 WorkQueueSets(size_t num_sets, const char* name); | |
| 26 ~WorkQueueSets(); | |
| 27 | |
| 28 // O(log num queues) | |
| 29 void AddQueue(WorkQueue* queue, size_t set_index); | |
| 30 | |
| 31 // O(log num queues) | |
| 32 void RemoveQueue(WorkQueue* work_queue); | |
| 33 | |
| 34 // O(log num queues) | |
| 35 void ChangeSetIndex(WorkQueue* queue, size_t set_index); | |
| 36 | |
| 37 // O(log num queues) | |
| 38 void OnPushQueue(WorkQueue* work_queue); | |
| 39 | |
| 40 // If empty it's O(1) amortized, otherwise it's O(log num queues) | |
| 41 void OnPopQueue(WorkQueue* work_queue); | |
| 42 | |
| 43 // O(1) | |
| 44 bool GetOldestQueueInSet(size_t set_index, WorkQueue** out_work_queue) const; | |
| 45 | |
| 46 // O(1) | |
| 47 bool IsSetEmpty(size_t set_index) const; | |
| 48 | |
| 49 #if DCHECK_IS_ON() || !defined(NDEBUG) | |
| 50 // Note this iterates over everything in |enqueue_order_to_work_queue_maps_|. | |
| 51 // It's intended for use with DCHECKS and for testing | |
| 52 bool ContainsWorkQueueForTest(const WorkQueue* queue) const; | |
| 53 #endif | |
| 54 | |
| 55 const char* name() const { return name_; } | |
| 56 | |
| 57 private: | |
| 58 typedef std::map<EnqueueOrder, WorkQueue*> EnqueueOrderToWorkQueueMap; | |
| 59 std::vector<EnqueueOrderToWorkQueueMap> enqueue_order_to_work_queue_maps_; | |
| 60 const char* name_; | |
| 61 | |
| 62 DISALLOW_COPY_AND_ASSIGN(WorkQueueSets); | |
| 63 }; | |
| 64 | |
| 65 } // namespace internal | |
| 66 } // namespace scheduler | |
| 67 | |
| 68 #endif // COMPONENTS_SCHEDULER_BASE_WORK_QUEUE_SETS_H_ | |
| OLD | NEW |