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" | |
10 #include "platform/scheduler/DoubleBufferedDeque.h" | |
9 #include "wtf/Functional.h" | 11 #include "wtf/Functional.h" |
10 #include "wtf/Noncopyable.h" | 12 #include "wtf/Noncopyable.h" |
13 #include "wtf/ThreadingPrimitives.h" | |
11 | 14 |
12 namespace blink { | 15 namespace blink { |
13 class WebThread; | 16 class WebThread; |
14 } | 17 } |
15 | 18 |
16 namespace blink { | 19 namespace blink { |
17 | 20 |
18 class TraceLocation; | 21 class TraceLocation; |
19 | 22 |
20 // The scheduler is an opinionated gateway for arranging work to be run on the | 23 // The scheduler is an opinionated gateway for arranging work to be run on the |
(...skipping 12 matching lines...) Expand all Loading... | |
33 | 36 |
34 // The following entrypoints are used to schedule different types of tasks | 37 // The following entrypoints are used to schedule different types of tasks |
35 // to be run on the main thread. They can be called from any thread. | 38 // to be run on the main thread. They can be called from any thread. |
36 void postInputTask(const TraceLocation&, const Task&); | 39 void postInputTask(const TraceLocation&, const Task&); |
37 void postCompositorTask(const TraceLocation&, const Task&); | 40 void postCompositorTask(const TraceLocation&, const Task&); |
38 void postTask(const TraceLocation&, const Task&); // For generic (low priori ty) tasks. | 41 void postTask(const TraceLocation&, const Task&); // For generic (low priori ty) tasks. |
39 void postIdleTask(const IdleTask&); // For non-critical tasks which may be r eordered relative to other task types. | 42 void postIdleTask(const IdleTask&); // For non-critical tasks which may be r eordered relative to other task types. |
40 | 43 |
41 // Returns true if there is high priority work pending on the main thread | 44 // Returns true if there is high priority work pending on the main thread |
42 // and the caller should yield to let the scheduler service that work. | 45 // and the caller should yield to let the scheduler service that work. |
43 // Can be called on the main thread. | 46 // Can be called on any thread. |
44 bool shouldYieldForHighPriorityWork(); | 47 bool shouldYieldForHighPriorityWork(); |
45 | 48 |
46 // The shared timer can be used to schedule a periodic callback which may | 49 // The shared timer can be used to schedule a periodic callback which may |
47 // get preempted by higher priority work. | 50 // get preempted by higher priority work. |
48 void setSharedTimerFiredFunction(void (*function)()); | 51 void setSharedTimerFiredFunction(void (*function)()); |
49 void setSharedTimerFireInterval(double); | 52 void setSharedTimerFireInterval(double); |
50 void stopSharedTimer(); | 53 void stopSharedTimer(); |
51 | 54 |
52 private: | 55 private: |
53 Scheduler(); | 56 Scheduler(); |
54 ~Scheduler(); | 57 ~Scheduler(); |
55 | 58 |
56 void scheduleTask(const TraceLocation&, const Task&); | |
57 void scheduleIdleTask(const IdleTask&); | 59 void scheduleIdleTask(const IdleTask&); |
58 | 60 |
59 static void sharedTimerAdapter(); | 61 static void sharedTimerAdapter(); |
60 void tickSharedTimer(); | 62 void tickSharedTimer(); |
61 | 63 |
62 static Scheduler* s_sharedScheduler; | 64 static Scheduler* s_sharedScheduler; |
65 | |
66 class TracedTask { | |
67 public: | |
68 TracedTask(const Task& task, const TraceLocation& location) | |
69 : m_task(task) | |
70 , m_location(location) { } | |
71 | |
72 void run(); | |
73 | |
74 private: | |
75 Task m_task; | |
76 TraceLocation m_location; | |
77 }; | |
78 | |
79 // These members can be accessed from any thread. | |
63 blink::WebThread* m_mainThread; | 80 blink::WebThread* m_mainThread; |
81 DoubleBufferedDeque<TracedTask> m_pendingInputTasks; | |
82 DoubleBufferedDeque<TracedTask> m_pendingCompositorTasks; | |
83 void (*m_sharedTimerFunction)(); | |
84 volatile int m_mainThreadTaskRunnerCount; | |
64 | 85 |
65 void (*m_sharedTimerFunction)(); | 86 void maybePostMainThreadPendingHighPriorityTaskRunner(); |
Sami
2014/08/08 15:31:13
Can you move these up before the data members?
alexclarke
2014/08/08 15:47:46
Done.
| |
87 void runHighPriorityTasks(); | |
88 | |
89 class MainThreadPendingTaskRunner; | |
Sami
2014/08/08 15:31:13
These should also go right after the private: labe
alexclarke
2014/08/08 15:47:46
Done.
| |
90 class MainThreadPendingHighPriorityTaskRunner; | |
91 friend class MainThreadPendingTaskRunner; | |
92 friend class MainThreadPendingHighPriorityTaskRunner; | |
66 }; | 93 }; |
67 | 94 |
68 } // namespace blink | 95 } // namespace blink |
69 | 96 |
70 #endif // Scheduler_h | 97 #endif // Scheduler_h |
OLD | NEW |