OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef Scheduler_h | 5 #ifndef Scheduler_h |
6 #define Scheduler_h | 6 #define Scheduler_h |
7 | 7 |
8 #include "platform/PlatformExport.h" | 8 #include "platform/PlatformExport.h" |
9 #include "platform/TraceLocation.h" | 9 #include "platform/scheduler/TracedTask.h" |
10 #include "wtf/DoubleBufferedDeque.h" | 10 #include "wtf/DoubleBufferedDeque.h" |
11 #include "wtf/Functional.h" | 11 #include "wtf/Functional.h" |
12 #include "wtf/Noncopyable.h" | 12 #include "wtf/Noncopyable.h" |
13 #include "wtf/ThreadingPrimitives.h" | 13 #include "wtf/ThreadingPrimitives.h" |
14 | 14 |
15 namespace blink { | 15 namespace blink { |
16 class WebThread; | 16 class WebThread; |
17 struct WebBeginFrameArgs; | 17 struct WebBeginFrameArgs; |
18 | 18 |
19 // The scheduler is an opinionated gateway for arranging work to be run on the | 19 // The scheduler is an opinionated gateway for arranging work to be run on the |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 class MainThreadPendingTaskRunner; | 62 class MainThreadPendingTaskRunner; |
63 class MainThreadPendingHighPriorityTaskRunner; | 63 class MainThreadPendingHighPriorityTaskRunner; |
64 friend class MainThreadPendingTaskRunner; | 64 friend class MainThreadPendingTaskRunner; |
65 friend class MainThreadPendingHighPriorityTaskRunner; | 65 friend class MainThreadPendingHighPriorityTaskRunner; |
66 | 66 |
67 enum SchedulerPolicy { | 67 enum SchedulerPolicy { |
68 Normal, | 68 Normal, |
69 CompositorPriority, | 69 CompositorPriority, |
70 }; | 70 }; |
71 | 71 |
72 class TracedTask { | |
73 public: | |
74 TracedTask(const Task& task, const TraceLocation& location) | |
75 : m_task(task) | |
76 , m_location(location) { } | |
77 | |
78 void run(); | |
79 | |
80 private: | |
81 Task m_task; | |
82 TraceLocation m_location; | |
83 }; | |
84 | |
85 Scheduler(); | 72 Scheduler(); |
86 virtual ~Scheduler(); | 73 virtual ~Scheduler(); |
87 | 74 |
| 75 void scheduleIdleTask(const TraceLocation&, const IdleTask&); |
| 76 void postHighPriorityTaskInternal(const TraceLocation&, const Task&, const c
har* traceName); |
| 77 |
88 static void sharedTimerAdapter(); | 78 static void sharedTimerAdapter(); |
89 | 79 |
90 | |
91 // Start of main thread only members ----------------------------------- | 80 // Start of main thread only members ----------------------------------- |
92 | 81 |
93 // Only does work in CompositorPriority mode. Returns true if any work was d
one. | 82 // Only does work in CompositorPriority mode. Returns true if any work was d
one. |
94 bool runPendingHighPriorityTasksIfInCompositorPriority(); | 83 bool runPendingHighPriorityTasksIfInCompositorPriority(); |
95 | 84 |
96 // Returns true if any work was done. | 85 // Returns true if any work was done. |
97 bool swapQueuesAndRunPendingTasks(); | 86 bool swapQueuesAndRunPendingTasks(); |
98 | 87 |
99 void swapQueuesRunPendingTasksAndAllowHighPriorityTaskRunnerPosting(); | 88 void swapQueuesRunPendingTasksAndAllowHighPriorityTaskRunnerPosting(); |
100 | 89 |
101 // Returns true if any work was done. | 90 // Returns true if any work was done. |
102 bool executeHighPriorityTasks(Deque<TracedTask>&); | 91 bool executeHighPriorityTasks(Deque<TracedTask>&); |
103 | 92 |
104 // Return the current SchedulerPolicy. | 93 // Return the current SchedulerPolicy. |
105 SchedulerPolicy schedulerPolicy() const; | 94 SchedulerPolicy schedulerPolicy() const; |
106 | 95 |
107 void maybeEnterNormalSchedulerPolicy(); | 96 void maybeEnterNormalSchedulerPolicy(); |
108 | 97 |
109 // Must be called while m_pendingTasksMutex is locked. | 98 // Must be called while m_pendingTasksMutex is locked. |
110 void maybePostMainThreadPendingHighPriorityTaskRunner(); | 99 void maybePostMainThreadPendingHighPriorityTaskRunner(); |
111 | 100 |
112 void tickSharedTimer(); | 101 void tickSharedTimer(); |
113 | 102 |
114 void (*m_sharedTimerFunction)(); | 103 void (*m_sharedTimerFunction)(); |
115 | 104 |
116 // End of main thread only members ------------------------------------- | 105 // End of main thread only members ------------------------------------- |
117 | 106 |
118 | |
119 void scheduleIdleTask(const TraceLocation&, const IdleTask&); | |
120 | |
121 bool hasPendingHighPriorityWork() const; | 107 bool hasPendingHighPriorityWork() const; |
122 | 108 |
123 void enterSchedulerPolicyLocked(SchedulerPolicy); | 109 void enterSchedulerPolicyLocked(SchedulerPolicy); |
124 | 110 |
125 void enterSchedulerPolicy(SchedulerPolicy); | 111 void enterSchedulerPolicy(SchedulerPolicy); |
126 | 112 |
127 static Scheduler* s_sharedScheduler; | 113 static Scheduler* s_sharedScheduler; |
128 | 114 |
129 WebThread* m_mainThread; | 115 WebThread* m_mainThread; |
130 | 116 |
131 // This mutex protects calls to the pending task queue, m_highPriorityTaskRu
nnerPosted and | 117 // This mutex protects calls to the pending task queue, m_highPriorityTaskRu
nnerPosted and |
132 // m_compositorPriorityPolicyEndTimeSeconds. | 118 // m_compositorPriorityPolicyEndTimeSeconds. |
133 Mutex m_pendingTasksMutex; | 119 Mutex m_pendingTasksMutex; |
134 DoubleBufferedDeque<TracedTask> m_pendingHighPriorityTasks; | 120 DoubleBufferedDeque<TracedTask> m_pendingHighPriorityTasks; |
135 double m_compositorPriorityPolicyEndTimeSeconds; | 121 double m_compositorPriorityPolicyEndTimeSeconds; |
136 | 122 |
| 123 // Declared volatile as it is atomically incremented. |
137 volatile int m_highPriorityTaskCount; | 124 volatile int m_highPriorityTaskCount; |
| 125 |
138 bool m_highPriorityTaskRunnerPosted; | 126 bool m_highPriorityTaskRunnerPosted; |
139 | 127 |
140 // Don't access m_schedulerPolicy directly, use enterSchedulerPolicyLocked a
nd SchedulerPolicy instead. | 128 // Don't access m_schedulerPolicy directly, use enterSchedulerPolicyLocked a
nd SchedulerPolicy instead. |
141 volatile int m_schedulerPolicy; | 129 volatile int m_schedulerPolicy; |
142 }; | 130 }; |
143 | 131 |
144 } // namespace blink | 132 } // namespace blink |
145 | 133 |
146 #endif // Scheduler_h | 134 #endif // Scheduler_h |
OLD | NEW |