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/scheduler/TracedTask.h" | 9 #include "platform/scheduler/TracedTask.h" |
10 #include "wtf/DoubleBufferedDeque.h" | 10 #include "wtf/DoubleBufferedDeque.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 enum SchedulerPolicy { | 68 enum SchedulerPolicy { |
69 Normal, | 69 Normal, |
70 CompositorPriority, | 70 CompositorPriority, |
71 }; | 71 }; |
72 | 72 |
73 Scheduler(); | 73 Scheduler(); |
74 virtual ~Scheduler(); | 74 virtual ~Scheduler(); |
75 | 75 |
76 void scheduleIdleTask(const TraceLocation&, const IdleTask&); | 76 void scheduleIdleTask(const TraceLocation&, const IdleTask&); |
77 void postHighPriorityTaskInternal(const TraceLocation&, const Task&, const c
har* traceName); | 77 void postHighPriorityTaskInternal(const TraceLocation&, const Task&, const c
har* traceName); |
| 78 void didRunHighPriorityTask(); |
78 | 79 |
79 static void sharedTimerAdapter(); | 80 static void sharedTimerAdapter(); |
80 | 81 |
81 // Start of main thread only members ----------------------------------- | 82 // Start of main thread only members ----------------------------------- |
82 | 83 |
83 // Only does work in CompositorPriority mode. Returns true if any work was d
one. | 84 // Only does work in CompositorPriority mode. Returns true if any work was d
one. |
84 bool runPendingHighPriorityTasksIfInCompositorPriority(); | 85 bool runPendingHighPriorityTasksIfInCompositorPriority(); |
85 | 86 |
86 // Returns true if any work was done. | 87 // Returns true if any work was done. |
87 bool swapQueuesAndRunPendingTasks(); | |
88 | |
89 void swapQueuesRunPendingTasksAndAllowHighPriorityTaskRunnerPosting(); | |
90 | |
91 // Returns true if any work was done. | |
92 bool executeHighPriorityTasks(Deque<TracedTask>&); | 88 bool executeHighPriorityTasks(Deque<TracedTask>&); |
93 | 89 |
94 // Return the current SchedulerPolicy. | 90 // Return the current SchedulerPolicy. |
95 SchedulerPolicy schedulerPolicy() const; | 91 SchedulerPolicy schedulerPolicy() const; |
96 | 92 |
97 void maybeEnterNormalSchedulerPolicy(); | 93 void updatePolicy(); |
98 | |
99 // Must be called while m_pendingTasksMutex is locked. | |
100 void maybePostMainThreadPendingHighPriorityTaskRunner(); | |
101 | 94 |
102 void tickSharedTimer(); | 95 void tickSharedTimer(); |
103 | 96 |
104 void (*m_sharedTimerFunction)(); | 97 void (*m_sharedTimerFunction)(); |
105 | 98 |
106 // End of main thread only members ------------------------------------- | 99 // End of main thread only members ------------------------------------- |
107 | 100 |
108 bool hasPendingHighPriorityWork() const; | |
109 | |
110 void enterSchedulerPolicyLocked(SchedulerPolicy); | 101 void enterSchedulerPolicyLocked(SchedulerPolicy); |
111 | |
112 void enterSchedulerPolicy(SchedulerPolicy); | 102 void enterSchedulerPolicy(SchedulerPolicy); |
113 | 103 |
114 static Scheduler* s_sharedScheduler; | 104 static Scheduler* s_sharedScheduler; |
115 | 105 |
116 WebThread* m_mainThread; | 106 WebThread* m_mainThread; |
117 | 107 |
118 // This mutex protects calls to the pending task queue, m_highPriorityTaskRu
nnerPosted and | |
119 // m_compositorPriorityPolicyEndTimeSeconds. | |
120 Mutex m_pendingTasksMutex; | |
121 DoubleBufferedDeque<TracedTask> m_pendingHighPriorityTasks; | |
122 double m_compositorPriorityPolicyEndTimeSeconds; | |
123 | |
124 // Declared volatile as it is atomically incremented. | 108 // Declared volatile as it is atomically incremented. |
125 volatile int m_highPriorityTaskCount; | 109 volatile int m_highPriorityTaskCount; |
126 | 110 |
127 bool m_highPriorityTaskRunnerPosted; | 111 bool m_highPriorityTaskRunnerPosted; |
128 | 112 |
129 // Don't access m_schedulerPolicy directly, use enterSchedulerPolicyLocked a
nd SchedulerPolicy instead. | 113 Mutex m_policyStateMutex; |
| 114 double m_compositorPriorityPolicyEndTimeSeconds; |
| 115 |
| 116 // Don't access m_schedulerPolicy directly, use enterSchedulerPolicyLocked a
nd schedulerPolicy instead. |
130 volatile int m_schedulerPolicy; | 117 volatile int m_schedulerPolicy; |
131 }; | 118 }; |
132 | 119 |
133 } // namespace blink | 120 } // namespace blink |
134 | 121 |
135 #endif // Scheduler_h | 122 #endif // Scheduler_h |
OLD | NEW |