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 "public/platform/WebThread.h" | |
11 #include "wtf/Deque.h" | |
9 #include "wtf/Functional.h" | 12 #include "wtf/Functional.h" |
10 #include "wtf/Noncopyable.h" | 13 #include "wtf/Noncopyable.h" |
14 #include "wtf/ThreadingPrimitives.h" | |
11 | 15 |
12 namespace blink { | 16 namespace blink { |
13 class WebThread; | 17 class WebThread; |
14 } | 18 } |
15 | 19 |
16 namespace blink { | 20 namespace blink { |
17 | 21 |
18 class TraceLocation; | 22 class TraceLocation; |
19 | 23 |
20 // The scheduler is an opinionated gateway for arranging work to be run on the | 24 // The scheduler is an opinionated gateway for arranging work to be run on the |
(...skipping 21 matching lines...) Expand all Loading... | |
42 // and the caller should yield to let the scheduler service that work. | 46 // and the caller should yield to let the scheduler service that work. |
43 // Can be called on the main thread. | 47 // Can be called on the main thread. |
44 bool shouldYieldForHighPriorityWork(); | 48 bool shouldYieldForHighPriorityWork(); |
45 | 49 |
46 // The shared timer can be used to schedule a periodic callback which may | 50 // The shared timer can be used to schedule a periodic callback which may |
47 // get preempted by higher priority work. | 51 // get preempted by higher priority work. |
48 void setSharedTimerFiredFunction(void (*function)()); | 52 void setSharedTimerFiredFunction(void (*function)()); |
49 void setSharedTimerFireInterval(double); | 53 void setSharedTimerFireInterval(double); |
50 void stopSharedTimer(); | 54 void stopSharedTimer(); |
51 | 55 |
56 void runPendingTasks(); | |
Sami
2014/08/07 14:24:45
This one doesn't need to be public, does it?
| |
57 | |
52 private: | 58 private: |
53 Scheduler(); | 59 Scheduler(); |
54 ~Scheduler(); | 60 ~Scheduler(); |
55 | 61 |
56 void scheduleTask(const TraceLocation&, const Task&); | |
57 void scheduleIdleTask(const IdleTask&); | 62 void scheduleIdleTask(const IdleTask&); |
58 | 63 |
59 static void sharedTimerAdapter(); | 64 static void sharedTimerAdapter(); |
60 void tickSharedTimer(); | 65 void tickSharedTimer(); |
61 | 66 |
62 static Scheduler* s_sharedScheduler; | 67 static Scheduler* s_sharedScheduler; |
68 | |
69 class TracedTask { | |
70 public: | |
71 TracedTask(Task task, TraceLocation location) | |
Sami
2014/08/07 14:24:45
const Task& and const TraceLocation&
alexclarke
2014/08/07 15:15:29
Done.
| |
72 : m_task(task) | |
73 , m_location(location) { } | |
74 | |
75 void run(); | |
76 | |
77 private: | |
78 Task m_task; | |
79 TraceLocation m_location; | |
80 }; | |
81 | |
82 class LockingTracedTaskDeque { | |
83 public: | |
84 void append(const TracedTask& value) | |
85 { | |
86 Locker<Mutex> lock(m_mutex); | |
87 m_queue.append(value); | |
88 } | |
89 | |
90 bool isEmpty() | |
Sami
2014/08/07 14:24:45
Could we somehow combine isEmpty() and takeFirst()
alexclarke
2014/08/07 15:15:29
Done.
| |
91 { | |
92 Locker<Mutex> lock(m_mutex); | |
93 return m_queue.isEmpty(); | |
94 } | |
95 | |
96 TracedTask takeFirst() | |
97 { | |
98 Locker<Mutex> lock(m_mutex); | |
99 return m_queue.takeFirst(); | |
100 } | |
101 | |
102 private: | |
103 WTF::Deque<TracedTask> m_queue; | |
104 Mutex m_mutex; | |
105 }; | |
106 | |
107 // These members can be accessed from any thread. | |
63 blink::WebThread* m_mainThread; | 108 blink::WebThread* m_mainThread; |
109 LockingTracedTaskDeque m_pendingInputTasks; | |
110 LockingTracedTaskDeque m_pendingCompositorTasks; | |
111 LockingTracedTaskDeque m_pendingLowPriorityTasks; | |
112 void (*m_sharedTimerFunction)(); | |
Sami
2014/08/07 14:24:45
This member should only be used on the main thread
| |
64 | 113 |
65 void (*m_sharedTimerFunction)(); | 114 void maybePostTaskLoopOnMainThread(); |
Sami
2014/08/07 14:24:45
Could you move these two before the data member de
| |
115 void runHighPriorityTasks(); | |
66 }; | 116 }; |
67 | 117 |
68 } // namespace blink | 118 } // namespace blink |
69 | 119 |
70 #endif // Scheduler_h | 120 #endif // Scheduler_h |
OLD | NEW |