summaryrefslogtreecommitdiffstats
path: root/components/scheduler/base/work_queue_sets.h
blob: 63ba7a05b6741d704ce13aa5dcaa2e6ce8195658 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_SCHEDULER_BASE_WORK_QUEUE_SETS_H_
#define COMPONENTS_SCHEDULER_BASE_WORK_QUEUE_SETS_H_

#include <stddef.h>

#include <map>
#include <vector>

#include "base/macros.h"
#include "base/trace_event/trace_event_argument.h"
#include "components/scheduler/base/task_queue_impl.h"
#include "components/scheduler/scheduler_export.h"

namespace scheduler {
namespace internal {
class TaskQueueImpl;

class SCHEDULER_EXPORT WorkQueueSets {
 public:
  explicit WorkQueueSets(size_t num_sets);
  ~WorkQueueSets();

  // O(log num queues)
  void RemoveQueue(WorkQueue* work_queue);

  // O(log num queues)
  void AssignQueueToSet(WorkQueue* queue, size_t set_index);

  // O(log num queues)
  void OnPushQueue(WorkQueue* work_queue);

  // If empty it's O(1) amortized, otherwise it's O(log num queues)
  void OnPopQueue(WorkQueue* work_queue);

  // O(1)
  bool GetOldestQueueInSet(size_t set_index, WorkQueue** out_work_queue) const;

  // O(1)
  bool IsSetEmpty(size_t set_index) const;

 private:
  typedef std::map<EnqueueOrder, WorkQueue*> EnqueueOrderToWorkQueueMap;
  std::vector<EnqueueOrderToWorkQueueMap> enqueue_order_to_work_queue_maps_;

  DISALLOW_COPY_AND_ASSIGN(WorkQueueSets);
};

}  // namespace internal
}  // namespace scheduler

#endif  // COMPONENTS_SCHEDULER_BASE_WORK_QUEUE_SETS_H_