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

Side by Side Diff: content/renderer/scheduler/renderer_scheduler_selector.h

Issue 657953004: content: Add RendererTaskQueueSelector. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address review comments. Created 6 years, 1 month 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 2014 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 CONTENT_RENDERER_SCHEDULER_RENDERER_SCHEDULER_POLICY_H_
no sievers 2014/10/28 01:21:00 CONTENT_RENDERER_SCHEDULER_RENDERER_SCHEDULER_POLI
rmcilroy 2014/10/28 12:37:41 Changed to CONTENT_RENDERER_SCHEDULER_RENDERER_TAS
6 #define CONTENT_RENDERER_SCHEDULER_RENDERER_SCHEDULER_POLICY_H_
7
8 #include <set>
9
10 #include "base/threading/thread_checker.h"
11 #include "content/renderer/scheduler/task_queue_selector.h"
12
13 namespace content {
14
15 // A RendererSchedulerSelector is a TaskQueueSelector which is used by the
no sievers 2014/10/28 01:21:01 nit: Why is it not called RendererTaskQueueSelecto
rmcilroy 2014/10/28 12:37:41 Good point, done :).
16 // RendererScheduler to enable prioritization of particular queues depending on
17 // circumstances.
no sievers 2014/10/28 01:21:01 nit: "priorities" rather than "circumstances"?
rmcilroy 2014/10/28 12:37:42 dropped "depending on circumstances" entirely
18 class RendererSchedulerSelector : public TaskQueueSelector {
19 public:
20 enum QueuePriority {
21 // Queues with control priority will run before any other queue, and will
22 // explicitly starve other queues. Typically this should only be used for
23 // private queues which perform control operations.
24 kControlPriority,
no sievers 2014/10/28 01:21:00 nit: CONTROL_PRIORITY etc. (macro-style) for Chrom
rmcilroy 2014/10/28 12:37:42 Done.
25 // Queues with high priority will be selected preferentially over normal or
26 // best effort queues. The selector will ensure that high priority queues
27 // cannot completely starve normal priority queues.
28 kHighPriority,
29 // Queues with normal priority are the default.
30 kNormalPriority,
31 // Queues with best effort priority will only be run if all other queues are
32 // empty. They can be starved by the other queues.
33 kBestEffortPriority,
34 // Must be the last entry.
35 kQueuePriorityCount,
36 kFirstQueuePriority = kControlPriority,
37 };
38
39 RendererSchedulerSelector();
40 virtual ~RendererSchedulerSelector();
no sievers 2014/10/28 01:21:00 nit: ~RendererSchedulerSelector() override;
rmcilroy 2014/10/28 12:37:41 Done.
41
42 // Set the priority of |queue_index| to |priority|.
43 void SetQueuePriority(size_t queue_index, QueuePriority priority);
44
45 // Enable the |queue_index| with a priority of |priority|. By default all
46 // queues are enabled with normal priority.
47 void EnableQueue(size_t queue_index, QueuePriority priority);
48
49 // Disable the |queue_index|.
50 void DisableQueue(size_t queue_index);
51
52 // TaskQueueSelector implementation:
53 void RegisterWorkQueues(
54 const std::vector<const base::TaskQueue*>& work_queues) override;
55 bool SelectWorkQueueToService(size_t* out_queue_index) override;
56
57 private:
58 // Returns true if queueA contains an older task than queueB.
59 static bool IsOlder(const base::TaskQueue* queueA,
60 const base::TaskQueue* queueB);
61
62 // Returns the priority which is next after |priority|.
63 static QueuePriority NextPriority(QueuePriority priority);
64
65 // Return true if |out_queue_index| indicates the index of the queue with
66 // the oldest pending task from the set of queues of |priority|, or
67 // false if all queues of that priority are empty.
68 bool ChooseOldestWithPriority(QueuePriority priority,
69 size_t* out_queue_index) const;
70
71 // Returns true if |queue_index| is enabled with the given |priority|.
72 bool QueueEnabledWithPriority(size_t queue_index,
73 QueuePriority priority) const;
74
75 // Number of high priority tasks which can be run before a normal priority
76 // task should be selected to prevent starvation.
77 // TODO(rmcilroy): Check if this is a good value.
78 static const size_t kMaxStarvationTasks = 5;
79
80 base::ThreadChecker main_thread_checker_;
81 std::vector<const base::TaskQueue*> work_queues_;
82 std::set<size_t> queue_priorities_[kQueuePriorityCount];
83 size_t starvation_count_;
no sievers 2014/10/28 01:21:01 nit: DISALLOW_COPY_AND_ASSIGN(...)
84 };
85
86 } // namespace content
87
88 #endif // CONTENT_RENDERER_SCHEDULER_RENDERER_SCHEDULER_POLICY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698