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/TraceLocation.h" |
10 #include "wtf/DoubleBufferedDeque.h" | 10 #include "wtf/DoubleBufferedDeque.h" |
(...skipping 24 matching lines...) Expand all Loading... | |
35 | 35 |
36 // Called to notify that a previously begun frame was committed. | 36 // Called to notify that a previously begun frame was committed. |
37 void didCommitFrameToCompositor(); | 37 void didCommitFrameToCompositor(); |
38 | 38 |
39 // The following entrypoints are used to schedule different types of tasks | 39 // The following entrypoints are used to schedule different types of tasks |
40 // to be run on the main thread. They can be called from any thread. | 40 // to be run on the main thread. They can be called from any thread. |
41 void postInputTask(const TraceLocation&, const Task&); | 41 void postInputTask(const TraceLocation&, const Task&); |
42 void postCompositorTask(const TraceLocation&, const Task&); | 42 void postCompositorTask(const TraceLocation&, const Task&); |
43 void postTask(const TraceLocation&, const Task&); // For generic (low priori ty) tasks. | 43 void postTask(const TraceLocation&, const Task&); // For generic (low priori ty) tasks. |
44 void postIdleTask(const TraceLocation&, const IdleTask&); // For non-critica l tasks which may be reordered relative to other task types. | 44 void postIdleTask(const TraceLocation&, const IdleTask&); // For non-critica l tasks which may be reordered relative to other task types. |
45 void postIpcTask(const TraceLocation&, const Task&); // For (low priority) t asks posted in response to IPCs | |
eseidel
2014/09/10 16:28:09
Are IPCs normally low? I would expect them to be
| |
45 | 46 |
46 // Returns true if there is high priority work pending on the main thread | 47 // Returns true if there is high priority work pending on the main thread |
47 // and the caller should yield to let the scheduler service that work. | 48 // and the caller should yield to let the scheduler service that work. |
48 // Can be called on any thread. | 49 // Can be called on any thread. |
49 bool shouldYieldForHighPriorityWork() const; | 50 bool shouldYieldForHighPriorityWork() const; |
50 | 51 |
51 // The shared timer can be used to schedule a periodic callback which may | 52 // The shared timer can be used to schedule a periodic callback which may |
52 // get preempted by higher priority work. | 53 // get preempted by higher priority work. |
53 void setSharedTimerFiredFunction(void (*function)()); | 54 void setSharedTimerFiredFunction(void (*function)()); |
54 void setSharedTimerFireInterval(double); | 55 void setSharedTimerFireInterval(double); |
55 void stopSharedTimer(); | 56 void stopSharedTimer(); |
56 | 57 |
58 // Returns the predicted next compositor start time based on data provided b y willBeginFrame. | |
59 double nextPredictedCompositorStart(); | |
eseidel
2014/09/10 16:28:09
Should this be on the Scheduler directly? Or some
| |
60 | |
61 // Returns the predicted next compositor deadline time based on data provide d by willBeginFrame. | |
62 double nextPredictedCompositorDeadline(); | |
63 | |
57 private: | 64 private: |
58 class MainThreadPendingTaskRunner; | 65 class MainThreadPendingTaskRunner; |
59 class MainThreadPendingHighPriorityTaskRunner; | 66 class MainThreadPendingHighPriorityTaskRunner; |
67 class MainThreadPendingLowPriorityTaskRunner; | |
60 friend class MainThreadPendingTaskRunner; | 68 friend class MainThreadPendingTaskRunner; |
61 friend class MainThreadPendingHighPriorityTaskRunner; | 69 friend class MainThreadPendingHighPriorityTaskRunner; |
70 friend class MainThreadPendingLowPriorityTaskRunner; | |
62 | 71 |
63 class TracedTask { | 72 class TracedTask { |
64 public: | 73 public: |
65 TracedTask(const Task& task, const TraceLocation& location) | 74 TracedTask(const Task& task, const TraceLocation& location) |
66 : m_task(task) | 75 : m_task(task) |
67 , m_location(location) { } | 76 , m_location(location) { } |
68 | 77 |
69 void run(); | 78 void run(); |
70 | 79 |
71 private: | 80 private: |
72 Task m_task; | 81 Task m_task; |
73 TraceLocation m_location; | 82 TraceLocation m_location; |
74 }; | 83 }; |
75 | 84 |
76 Scheduler(); | 85 Scheduler(); |
77 ~Scheduler(); | 86 ~Scheduler(); |
78 | 87 |
79 void scheduleIdleTask(const TraceLocation&, const IdleTask&); | 88 void scheduleIdleTask(const TraceLocation&, const IdleTask&); |
80 | 89 |
81 static void sharedTimerAdapter(); | 90 static void sharedTimerAdapter(); |
82 void tickSharedTimer(); | 91 void tickSharedTimer(); |
83 | 92 |
84 bool hasPendingHighPriorityWork() const; | 93 bool hasPendingHighPriorityWork() const; |
85 bool swapQueuesAndRunPendingTasks(); | 94 bool runPendingHighPrioirtyTasks(); |
86 void swapQueuesRunPendingTasksAndAllowHighPriorityTaskRunnerPosting(); | 95 void runPendingHighPriorityTasksAndAllowTaskRunnerPosting(); |
96 void runPendingLowPriorityTasks(); | |
97 | |
98 // If m_activeLowPrioirtyQueue is null or empty, then reloaded it from m_pen dingLowPriorityTasks. | |
99 void reloadEmptyLowPrioirtyQueue(); | |
87 | 100 |
88 // Returns true if any work was done. | 101 // Returns true if any work was done. |
89 bool executeHighPriorityTasks(Deque<TracedTask>&); | 102 bool executeHighPriorityTasks(Deque<TracedTask>&); |
90 | 103 |
91 // Must be called while m_pendingTasksMutex is locked. | 104 // Must be called while m_pendingTasksMutex is locked. |
92 void maybePostMainThreadPendingHighPriorityTaskRunner(); | 105 void maybePostMainThreadPendingHighPriorityTaskRunner(); |
93 | 106 |
107 // Must be called while m_pendingTasksMutex is locked. | |
eseidel
2014/09/10 16:28:09
Why not just ASSERT that the thread is locked in t
| |
108 void maybePostMainThreadPendingLowPriorityTaskRunner(double currentTime); | |
109 | |
110 // Must be called while m_pendingTasksMutex is locked. | |
111 double nextPredictedCompositorStartInternal(double currentTime); | |
112 | |
113 // Must be called while m_pendingTasksMutex is locked. | |
114 double nextPredictedCompositorDeadlineInternal(double currentTime); | |
115 | |
94 static Scheduler* s_sharedScheduler; | 116 static Scheduler* s_sharedScheduler; |
95 | 117 |
96 // Should only be accessed from the main thread. | 118 // Should only be accessed from the main thread. |
97 void (*m_sharedTimerFunction)(); | 119 void (*m_sharedTimerFunction)(); |
98 | 120 |
99 // These members can be accessed from any thread. | 121 // These members can be accessed from any thread. |
100 WebThread* m_mainThread; | 122 WebThread* m_mainThread; |
101 | 123 |
102 // This mutex protects calls to the pending task queue and m_highPriorityTas kRunnerPosted. | 124 // This mutex protects all members of m_mutexProtected. |
103 Mutex m_pendingTasksMutex; | 125 Mutex m_pendingTasksMutex; |
104 DoubleBufferedDeque<TracedTask> m_pendingHighPriorityTasks; | 126 struct { |
127 DoubleBufferedDeque<TracedTask> m_pendingHighPriorityTasks; | |
128 DoubleBufferedDeque<TracedTask> m_pendingLowPriorityTasks; | |
129 bool m_highPriorityTaskRunnerPosted; | |
130 bool m_lowPriorityTaskRunnerPosted; | |
131 } m_mutexProtected; | |
eseidel
2014/09/10 16:28:09
I'm not sure this gets you much. We certainly cou
| |
132 | |
133 double m_compositorStart; | |
134 double m_compositorDeadline; | |
135 double m_compositorInterval; | |
105 | 136 |
106 volatile int m_highPriorityTaskCount; | 137 volatile int m_highPriorityTaskCount; |
107 bool m_highPriorityTaskRunnerPosted; | 138 Deque<TracedTask>* m_activeLowPrioirtyQueue; |
139 | |
140 static const double s_maximumLowPrioirtyTaskExecutionTimeSeconds; | |
108 }; | 141 }; |
109 | 142 |
110 } // namespace blink | 143 } // namespace blink |
111 | 144 |
112 #endif // Scheduler_h | 145 #endif // Scheduler_h |
OLD | NEW |