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" |
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; |
| 17 struct WebBeginFrameArgs; |
16 | 18 |
17 // 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 |
18 // main thread. It decides which tasks get priority over others based on a | 20 // main thread. It decides which tasks get priority over others based on a |
19 // scheduling policy and the overall system state. | 21 // scheduling policy and the overall system state. |
20 class WebThread; | |
21 | |
22 class PLATFORM_EXPORT Scheduler { | 22 class PLATFORM_EXPORT Scheduler { |
23 WTF_MAKE_NONCOPYABLE(Scheduler); | 23 WTF_MAKE_NONCOPYABLE(Scheduler); |
24 public: | 24 public: |
25 typedef Function<void()> Task; | 25 typedef Function<void()> Task; |
26 // An IdleTask is passed an allotted time in CLOCK_MONOTONIC milliseconds an
d is expected to complete within this timeframe. | 26 // An IdleTask is passed an allotted time in CLOCK_MONOTONIC milliseconds an
d is expected to complete within this timeframe. |
27 typedef Function<void(double allottedTimeMs)> IdleTask; | 27 typedef Function<void(double allottedTimeMs)> IdleTask; |
28 | 28 |
29 static Scheduler* shared(); | 29 static Scheduler* shared(); |
30 static void initializeOnMainThread(); | 30 static void initializeOnMainThread(); |
31 static void shutdown(); | 31 static void shutdown(); |
32 | 32 |
| 33 // Called to notify about the start of a new frame. |
| 34 void willBeginFrame(const WebBeginFrameArgs&); |
| 35 |
| 36 // Called to notify that a previously begun frame was committed. |
| 37 void didCommitFrameToCompositor(); |
| 38 |
33 // The following entrypoints are used to schedule different types of tasks | 39 // The following entrypoints are used to schedule different types of tasks |
34 // 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. |
35 void postInputTask(const TraceLocation&, const Task&); | 41 void postInputTask(const TraceLocation&, const Task&); |
36 void postCompositorTask(const TraceLocation&, const Task&); | 42 void postCompositorTask(const TraceLocation&, const Task&); |
37 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. |
38 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. |
39 | 45 |
40 // Returns true if there is high priority work pending on the main thread | 46 // Returns true if there is high priority work pending on the main thread |
41 // 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. |
42 // Can be called on any thread. | 48 // Can be called on any thread. |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 Mutex m_pendingTasksMutex; | 103 Mutex m_pendingTasksMutex; |
98 DoubleBufferedDeque<TracedTask> m_pendingHighPriorityTasks; | 104 DoubleBufferedDeque<TracedTask> m_pendingHighPriorityTasks; |
99 | 105 |
100 volatile int m_highPriorityTaskCount; | 106 volatile int m_highPriorityTaskCount; |
101 bool m_highPriorityTaskRunnerPosted; | 107 bool m_highPriorityTaskRunnerPosted; |
102 }; | 108 }; |
103 | 109 |
104 } // namespace blink | 110 } // namespace blink |
105 | 111 |
106 #endif // Scheduler_h | 112 #endif // Scheduler_h |
OLD | NEW |