Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(25)

Side by Side Diff: components/scheduler/child/task_queue_selector.h

Issue 1374653003: scheduler: Add a base directory (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed gn clobber build. Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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_CHILD_TASK_QUEUE_SELECTOR_H_
6 #define COMPONENTS_SCHEDULER_CHILD_TASK_QUEUE_SELECTOR_H_
7
8 #include <set>
9
10 #include "base/compiler_specific.h"
11 #include "base/pending_task.h"
12 #include "base/threading/thread_checker.h"
13 #include "components/scheduler/child/task_queue_sets.h"
14 #include "components/scheduler/scheduler_export.h"
15
16 namespace scheduler {
17 namespace internal {
18
19 // TaskQueueSelector is used by the SchedulerHelper to enable prioritization
20 // of particular task queues.
21 class SCHEDULER_EXPORT TaskQueueSelector {
22 public:
23 TaskQueueSelector();
24 ~TaskQueueSelector();
25
26 // Set the priority of |queue| to |priority|.
27 void SetQueuePriority(internal::TaskQueueImpl* queue,
28 TaskQueue::QueuePriority priority);
29
30 // Whether |queue| is enabled.
31 bool IsQueueEnabled(const internal::TaskQueueImpl* queue) const;
32
33 // Called to register a queue that can be selected. This function is called
34 // on the main thread.
35 void AddQueue(internal::TaskQueueImpl* queue);
36
37 // The specified work will no longer be considered for selection. This
38 // function is called on the main thread.
39 void RemoveQueue(internal::TaskQueueImpl* queue);
40
41 // Called to choose the work queue from which the next task should be taken
42 // and run. Return true if |out_queue| indicates the queue to service or
43 // false to avoid running any task.
44 //
45 // This function is called on the main thread.
46 bool SelectQueueToService(internal::TaskQueueImpl** out_queue);
47
48 // Serialize the selector state for tracing.
49 void AsValueInto(base::trace_event::TracedValue* state) const;
50
51 class SCHEDULER_EXPORT Observer {
52 public:
53 virtual ~Observer() {}
54
55 // Called when |queue| transitions from disabled to enabled.
56 virtual void OnTaskQueueEnabled(internal::TaskQueueImpl* queue) = 0;
57 };
58
59 // Called once to set the Observer. This function is called
60 // on the main thread. If |observer| is null, then no callbacks will occur.
61 void SetTaskQueueSelectorObserver(Observer* observer);
62
63 TaskQueueSets* GetTaskQueueSets() { return &task_queue_sets_; }
64
65 // Returns true if all the enabled work queues are empty. Returns false
66 // otherwise.
67 bool EnabledWorkQueuesEmpty() const;
68
69 private:
70 // Returns the priority which is next after |priority|.
71 static TaskQueue::QueuePriority NextPriority(
72 TaskQueue::QueuePriority priority);
73
74 // Return true if |out_queue| contains the queue with the oldest pending task
75 // from the set of queues of |priority|, or false if all queues of that
76 // priority are empty.
77 bool ChooseOldestWithPriority(TaskQueue::QueuePriority priority,
78 internal::TaskQueueImpl** out_queue) const;
79
80 // Called whenever the selector chooses a task queue for execution with the
81 // priority |priority|.
82 void DidSelectQueueWithPriority(TaskQueue::QueuePriority priority);
83
84 // Number of high priority tasks which can be run before a normal priority
85 // task should be selected to prevent starvation.
86 // TODO(rmcilroy): Check if this is a good value.
87 static const size_t kMaxStarvationTasks = 5;
88
89 base::ThreadChecker main_thread_checker_;
90 TaskQueueSets task_queue_sets_;
91
92 size_t starvation_count_;
93 Observer* task_queue_selector_observer_; // NOT OWNED
94 DISALLOW_COPY_AND_ASSIGN(TaskQueueSelector);
95 };
96
97 } // namespace internal
98 } // namespace scheduler
99
100 #endif // COMPONENTS_SCHEDULER_CHILD_TASK_QUEUE_SELECTOR_H
OLDNEW
« no previous file with comments | « components/scheduler/child/task_queue_manager_unittest.cc ('k') | components/scheduler/child/task_queue_selector.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698