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/scheduler/TracedTask.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; | 16 class WebThread; |
17 struct WebBeginFrameArgs; | 17 struct WebBeginFrameArgs; |
18 | 18 |
19 // 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 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 private: |
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 class TracedTask { | |
64 public: | |
65 TracedTask(const Task& task, const TraceLocation& location) | |
66 : m_task(task) | |
67 , m_location(location) { } | |
68 | |
69 void run(); | |
70 | |
71 private: | |
72 Task m_task; | |
73 TraceLocation m_location; | |
74 }; | |
75 | |
76 Scheduler(); | 63 Scheduler(); |
77 ~Scheduler(); | 64 ~Scheduler(); |
78 | 65 |
79 void scheduleIdleTask(const TraceLocation&, const IdleTask&); | 66 void scheduleIdleTask(const TraceLocation&, const IdleTask&); |
67 void postHighPriorityTaskInternal(const TraceLocation&, const Task&, const c har* traceName); | |
80 | 68 |
81 static void sharedTimerAdapter(); | 69 static void sharedTimerAdapter(); |
82 void tickSharedTimer(); | 70 void tickSharedTimer(); |
83 | 71 |
84 bool hasPendingHighPriorityWork() const; | 72 bool hasPendingHighPriorityWork() const; |
85 bool swapQueuesAndRunPendingTasks(); | 73 bool swapQueuesAndRunPendingTasks(); |
86 void swapQueuesRunPendingTasksAndAllowHighPriorityTaskRunnerPosting(); | 74 void swapQueuesRunPendingTasksAndAllowHighPriorityTaskRunnerPosting(); |
87 | 75 |
88 // Returns true if any work was done. | 76 // Returns true if any work was done. |
89 bool executeHighPriorityTasks(Deque<TracedTask>&); | 77 bool executeHighPriorityTasks(Deque<TracedTask>&); |
90 | 78 |
91 // Must be called while m_pendingTasksMutex is locked. | 79 // Must be called while m_pendingTasksMutex is locked. |
92 void maybePostMainThreadPendingHighPriorityTaskRunner(); | 80 void maybePostMainThreadPendingHighPriorityTaskRunner(); |
93 | 81 |
94 static Scheduler* s_sharedScheduler; | 82 static Scheduler* s_sharedScheduler; |
95 | 83 |
96 // Should only be accessed from the main thread. | 84 // Should only be accessed from the main thread. |
97 void (*m_sharedTimerFunction)(); | 85 void (*m_sharedTimerFunction)(); |
98 | 86 |
99 // These members can be accessed from any thread. | 87 // These members can be accessed from any thread. |
100 WebThread* m_mainThread; | 88 WebThread* m_mainThread; |
101 | 89 |
102 // This mutex protects calls to the pending task queue and m_highPriorityTas kRunnerPosted. | 90 // This mutex protects calls to the pending task queue and m_highPriorityTas kRunnerPosted. |
103 Mutex m_pendingTasksMutex; | 91 Mutex m_pendingTasksMutex; |
104 DoubleBufferedDeque<TracedTask> m_pendingHighPriorityTasks; | 92 DoubleBufferedDeque<TracedTask> m_pendingHighPriorityTasks; |
105 | 93 |
94 // Declared volatile as they are atomically incremented. | |
Sami
2014/09/04 09:51:07
nit: s/they are/this is/.
picksi1
2014/09/05 08:28:33
Done.
| |
106 volatile int m_highPriorityTaskCount; | 95 volatile int m_highPriorityTaskCount; |
96 | |
107 bool m_highPriorityTaskRunnerPosted; | 97 bool m_highPriorityTaskRunnerPosted; |
108 }; | 98 }; |
109 | 99 |
110 } // namespace blink | 100 } // namespace blink |
111 | 101 |
112 #endif // Scheduler_h | 102 #endif // Scheduler_h |
OLD | NEW |