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 |
80 bool hasPendingHighPriorityWork() const; | 68 bool hasPendingHighPriorityWork() const; |
81 bool swapQueuesAndRunPendingTasks(); | 69 bool swapQueuesAndRunPendingTasks(); |
82 void swapQueuesRunPendingTasksAndAllowHighPriorityTaskRunnerPosting(); | 70 void swapQueuesRunPendingTasksAndAllowHighPriorityTaskRunnerPosting(); |
83 | 71 |
84 // Returns true if any work was done. | 72 // Returns true if any work was done. |
85 bool executeHighPriorityTasks(Deque<TracedTask>&); | 73 bool executeHighPriorityTasks(Deque<TracedTask>&); |
86 | 74 |
87 // Must be called while m_pendingTasksMutex is locked. | 75 // Must be called while m_pendingTasksMutex is locked. |
88 void maybePostMainThreadPendingHighPriorityTaskRunner(); | 76 void maybePostMainThreadPendingHighPriorityTaskRunner(); |
89 | 77 |
78 int generateFlowTraceID(); | |
eseidel
2014/09/02 16:19:25
No type?
picksi1
2014/09/03 16:32:57
I don't know what you are asking for here? Are you
| |
79 | |
90 static Scheduler* s_sharedScheduler; | 80 static Scheduler* s_sharedScheduler; |
91 | 81 |
92 // Should only be accessed from the main thread. | 82 // Should only be accessed from the main thread. |
93 void (*m_sharedTimerFunction)(); | 83 void (*m_sharedTimerFunction)(); |
94 | 84 |
95 // These members can be accessed from any thread. | 85 // These members can be accessed from any thread. |
96 WebThread* m_mainThread; | 86 WebThread* m_mainThread; |
97 | 87 |
98 // This mutex protects calls to the pending task queue and m_highPriorityTas kRunnerPosted. | 88 // This mutex protects calls to the pending task queue and m_highPriorityTas kRunnerPosted. |
99 Mutex m_pendingTasksMutex; | 89 Mutex m_pendingTasksMutex; |
100 DoubleBufferedDeque<TracedTask> m_pendingHighPriorityTasks; | 90 DoubleBufferedDeque<TracedTask> m_pendingHighPriorityTasks; |
101 | 91 |
92 // Declared volatile as they are atomically incremented. | |
102 volatile int m_highPriorityTaskCount; | 93 volatile int m_highPriorityTaskCount; |
94 volatile int m_nextFlowTraceID; | |
95 | |
103 bool m_highPriorityTaskRunnerPosted; | 96 bool m_highPriorityTaskRunnerPosted; |
104 }; | 97 }; |
105 | 98 |
106 } // namespace blink | 99 } // namespace blink |
107 | 100 |
108 #endif // Scheduler_h | 101 #endif // Scheduler_h |
OLD | NEW |