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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
47 // and the caller should yield to let the scheduler service that work. | 47 // and the caller should yield to let the scheduler service that work. |
48 // Can be called on any thread. | 48 // Can be called on any thread. |
49 bool shouldYieldForHighPriorityWork() const; | 49 bool shouldYieldForHighPriorityWork() const; |
50 | 50 |
51 // The shared timer can be used to schedule a periodic callback which may | 51 // The shared timer can be used to schedule a periodic callback which may |
52 // get preempted by higher priority work. | 52 // get preempted by higher priority work. |
53 void setSharedTimerFiredFunction(void (*function)()); | 53 void setSharedTimerFiredFunction(void (*function)()); |
54 void setSharedTimerFireInterval(double); | 54 void setSharedTimerFireInterval(double); |
55 void stopSharedTimer(); | 55 void stopSharedTimer(); |
56 | 56 |
57 private: | 57 protected: |
58 class MainThreadPendingTaskRunner; | 58 class MainThreadPendingTaskRunner; |
59 class MainThreadPendingHighPriorityTaskRunner; | 59 class MainThreadPendingHighPriorityTaskRunner; |
60 friend class MainThreadPendingTaskRunner; | 60 friend class MainThreadPendingTaskRunner; |
61 friend class MainThreadPendingHighPriorityTaskRunner; | 61 friend class MainThreadPendingHighPriorityTaskRunner; |
62 | 62 |
63 enum SchedulerPolicy { | |
64 Normal, | |
65 CompositorPriority, | |
66 }; | |
67 | |
63 class TracedTask { | 68 class TracedTask { |
64 public: | 69 public: |
65 TracedTask(const Task& task, const TraceLocation& location) | 70 TracedTask(const Task& task, const TraceLocation& location) |
66 : m_task(task) | 71 : m_task(task) |
67 , m_location(location) { } | 72 , m_location(location) { } |
68 | 73 |
69 void run(); | 74 void run(); |
70 | 75 |
71 private: | 76 private: |
72 Task m_task; | 77 Task m_task; |
73 TraceLocation m_location; | 78 TraceLocation m_location; |
74 }; | 79 }; |
75 | 80 |
76 Scheduler(); | 81 Scheduler(); |
77 ~Scheduler(); | 82 virtual ~Scheduler(); |
78 | |
79 void scheduleIdleTask(const TraceLocation&, const IdleTask&); | |
80 | 83 |
81 static void sharedTimerAdapter(); | 84 static void sharedTimerAdapter(); |
82 void tickSharedTimer(); | |
83 | 85 |
84 bool hasPendingHighPriorityWork() const; | 86 |
87 // Start of main thread only members ----------------------------------- | |
88 | |
89 // Only does work in CompositorPriority mode. Returns true if any work was d one. | |
90 bool runPendingHighPriorityTasksIfInCompositorPriority(); | |
91 | |
92 // Returns true if any work was done. | |
85 bool swapQueuesAndRunPendingTasks(); | 93 bool swapQueuesAndRunPendingTasks(); |
94 | |
86 void swapQueuesRunPendingTasksAndAllowHighPriorityTaskRunnerPosting(); | 95 void swapQueuesRunPendingTasksAndAllowHighPriorityTaskRunnerPosting(); |
87 | 96 |
88 // Returns true if any work was done. | 97 // Returns true if any work was done. |
89 bool executeHighPriorityTasks(Deque<TracedTask>&); | 98 bool executeHighPriorityTasks(Deque<TracedTask>&); |
90 | 99 |
100 // Return the current SchedulerPolicy. | |
101 SchedulerPolicy schedulerPolicy() const; | |
102 | |
103 void maybeEnterNormalschedulerPolicy(); | |
Sami
2014/09/11 11:32:18
Please capitalize "scheduler" here.
| |
104 | |
91 // Must be called while m_pendingTasksMutex is locked. | 105 // Must be called while m_pendingTasksMutex is locked. |
92 void maybePostMainThreadPendingHighPriorityTaskRunner(); | 106 void maybePostMainThreadPendingHighPriorityTaskRunner(); |
93 | 107 |
108 void tickSharedTimer(); | |
109 | |
110 void (*m_sharedTimerFunction)(); | |
111 | |
112 // End of main thread only members ------------------------------------- | |
113 | |
114 | |
115 void scheduleIdleTask(const TraceLocation&, const IdleTask&); | |
116 | |
117 bool hasPendingHighPriorityWork() const; | |
118 | |
119 void enterSchedulerPolicy(SchedulerPolicy); | |
120 | |
94 static Scheduler* s_sharedScheduler; | 121 static Scheduler* s_sharedScheduler; |
95 | 122 |
96 // Should only be accessed from the main thread. | |
97 void (*m_sharedTimerFunction)(); | |
98 | |
99 // These members can be accessed from any thread. | |
100 WebThread* m_mainThread; | 123 WebThread* m_mainThread; |
101 | 124 |
102 // This mutex protects calls to the pending task queue and m_highPriorityTas kRunnerPosted. | 125 // This mutex protects calls to the pending task queue and m_highPriorityTas kRunnerPosted. |
103 Mutex m_pendingTasksMutex; | 126 Mutex m_pendingTasksMutex; |
104 DoubleBufferedDeque<TracedTask> m_pendingHighPriorityTasks; | 127 DoubleBufferedDeque<TracedTask> m_pendingHighPriorityTasks; |
105 | 128 |
106 volatile int m_highPriorityTaskCount; | 129 volatile int m_highPriorityTaskCount; |
107 bool m_highPriorityTaskRunnerPosted; | 130 bool m_highPriorityTaskRunnerPosted; |
131 | |
132 // Don't access m_schedulerPolicy directly, use enterSchedulerPolicy and Sch edulerPolicy instead. | |
133 volatile int m_schedulerPolicy; | |
134 double m_compositorPriorityPolicyEndTimeSeconds; | |
Sami
2014/09/11 11:32:18
This is protected by m_pendingTasksMutex, right? C
| |
108 }; | 135 }; |
109 | 136 |
110 } // namespace blink | 137 } // namespace blink |
111 | 138 |
112 #endif // Scheduler_h | 139 #endif // Scheduler_h |
OLD | NEW |