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 } | 17 } |
18 | 18 |
19 namespace blink { | 19 namespace blink { |
(...skipping 29 matching lines...) Expand all Loading... |
49 void setSharedTimerFiredFunction(void (*function)()); | 49 void setSharedTimerFiredFunction(void (*function)()); |
50 void setSharedTimerFireInterval(double); | 50 void setSharedTimerFireInterval(double); |
51 void stopSharedTimer(); | 51 void stopSharedTimer(); |
52 | 52 |
53 private: | 53 private: |
54 class MainThreadPendingTaskRunner; | 54 class MainThreadPendingTaskRunner; |
55 class MainThreadPendingHighPriorityTaskRunner; | 55 class MainThreadPendingHighPriorityTaskRunner; |
56 friend class MainThreadPendingTaskRunner; | 56 friend class MainThreadPendingTaskRunner; |
57 friend class MainThreadPendingHighPriorityTaskRunner; | 57 friend class MainThreadPendingHighPriorityTaskRunner; |
58 | 58 |
59 class TracedTask { | |
60 public: | |
61 TracedTask(const Task& task, const TraceLocation& location) | |
62 : m_task(task) | |
63 , m_location(location) { } | |
64 | |
65 void run(); | |
66 | |
67 private: | |
68 Task m_task; | |
69 TraceLocation m_location; | |
70 }; | |
71 | |
72 Scheduler(); | 59 Scheduler(); |
73 ~Scheduler(); | 60 ~Scheduler(); |
74 | 61 |
75 void scheduleIdleTask(const TraceLocation&, const IdleTask&); | 62 void scheduleIdleTask(const TraceLocation&, const IdleTask&); |
| 63 void postHighPriorityTaskInternal(const TraceLocation&, const Task&, const c
har* traceName); |
76 | 64 |
77 static void sharedTimerAdapter(); | 65 static void sharedTimerAdapter(); |
78 void tickSharedTimer(); | 66 void tickSharedTimer(); |
79 | 67 |
| 68 |
80 bool hasPendingHighPriorityWork() const; | 69 bool hasPendingHighPriorityWork() const; |
81 bool swapQueuesAndRunPendingTasks(); | 70 bool swapQueuesAndRunPendingTasks(); |
82 void swapQueuesRunPendingTasksAndAllowHighPriorityTaskRunnerPosting(); | 71 void swapQueuesRunPendingTasksAndAllowHighPriorityTaskRunnerPosting(); |
83 | 72 |
84 // Returns true if any work was done. | 73 // Returns true if any work was done. |
85 bool executeHighPriorityTasks(Deque<TracedTask>&); | 74 bool executeHighPriorityTasks(Deque<TracedTask>&); |
86 | 75 |
87 // Must be called while m_pendingTasksMutex is locked. | 76 // Must be called while m_pendingTasksMutex is locked. |
88 void maybePostMainThreadPendingHighPriorityTaskRunner(); | 77 void maybePostMainThreadPendingHighPriorityTaskRunner(); |
89 | 78 |
| 79 int generateFlowTraceID(); |
| 80 |
90 static Scheduler* s_sharedScheduler; | 81 static Scheduler* s_sharedScheduler; |
91 | 82 |
92 // Should only be accessed from the main thread. | 83 // Should only be accessed from the main thread. |
93 void (*m_sharedTimerFunction)(); | 84 void (*m_sharedTimerFunction)(); |
94 | 85 |
95 // These members can be accessed from any thread. | 86 // These members can be accessed from any thread. |
96 WebThread* m_mainThread; | 87 WebThread* m_mainThread; |
97 | 88 |
98 // This mutex protects calls to the pending task queue and m_highPriorityTas
kRunnerPosted. | 89 // This mutex protects calls to the pending task queue and m_highPriorityTas
kRunnerPosted. |
99 Mutex m_pendingTasksMutex; | 90 Mutex m_pendingTasksMutex; |
100 DoubleBufferedDeque<TracedTask> m_pendingHighPriorityTasks; | 91 DoubleBufferedDeque<TracedTask> m_pendingHighPriorityTasks; |
101 | 92 |
| 93 // Declared volatile as they are atomically incremented. |
102 volatile int m_highPriorityTaskCount; | 94 volatile int m_highPriorityTaskCount; |
| 95 volatile int m_nextFlowTraceID; |
| 96 |
103 bool m_highPriorityTaskRunnerPosted; | 97 bool m_highPriorityTaskRunnerPosted; |
104 }; | 98 }; |
105 | 99 |
106 } // namespace blink | 100 } // namespace blink |
107 | 101 |
108 #endif // Scheduler_h | 102 #endif // Scheduler_h |
OLD | NEW |