Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(605)

Side by Side Diff: Source/platform/scheduler/Scheduler.h

Issue 595023002: Implement idle task scheduling. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/scheduler/TracedTask.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/OwnPtr.h"
13 #include "wtf/ThreadingPrimitives.h" 14 #include "wtf/ThreadingPrimitives.h"
14 15
15 namespace blink { 16 namespace blink {
16 class WebThread; 17 class WebThread;
17 struct WebBeginFrameArgs; 18 struct WebBeginFrameArgs;
18 19
19 // The scheduler is an opinionated gateway for arranging work to be run on the 20 // The scheduler is an opinionated gateway for arranging work to be run on the
20 // main thread. It decides which tasks get priority over others based on a 21 // main thread. It decides which tasks get priority over others based on a
21 // scheduling policy and the overall system state. 22 // scheduling policy and the overall system state.
22 class PLATFORM_EXPORT Scheduler { 23 class PLATFORM_EXPORT Scheduler {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 // get preempted by higher priority work. 58 // get preempted by higher priority work.
58 void setSharedTimerFiredFunction(void (*function)()); 59 void setSharedTimerFiredFunction(void (*function)());
59 void setSharedTimerFireInterval(double); 60 void setSharedTimerFireInterval(double);
60 void stopSharedTimer(); 61 void stopSharedTimer();
61 62
62 protected: 63 protected:
63 class MainThreadPendingTaskRunner; 64 class MainThreadPendingTaskRunner;
64 class MainThreadPendingHighPriorityTaskRunner; 65 class MainThreadPendingHighPriorityTaskRunner;
65 friend class MainThreadPendingTaskRunner; 66 friend class MainThreadPendingTaskRunner;
66 friend class MainThreadPendingHighPriorityTaskRunner; 67 friend class MainThreadPendingHighPriorityTaskRunner;
68 friend class TracedIdleTask;
67 69
68 enum SchedulerPolicy { 70 enum SchedulerPolicy {
69 Normal, 71 Normal,
70 CompositorPriority, 72 CompositorPriority,
71 }; 73 };
72 74
73 Scheduler(); 75 Scheduler();
74 virtual ~Scheduler(); 76 virtual ~Scheduler();
75 77
76 void scheduleIdleTask(const TraceLocation&, const IdleTask&);
77 void postHighPriorityTaskInternal(const TraceLocation&, const Task&, const c har* traceName); 78 void postHighPriorityTaskInternal(const TraceLocation&, const Task&, const c har* traceName);
79 void postIdleTaskInternal(const TraceLocation&, const IdleTask&, const char* traceName);
78 80
79 static void sharedTimerAdapter(); 81 static void sharedTimerAdapter();
80 82
81 // Start of main thread only members ----------------------------------- 83 // Start of main thread only members -----------------------------------
82 84
83 // Only does work in CompositorPriority mode. Returns true if any work was d one. 85 // Only does work in CompositorPriority mode. Returns true if any work was d one.
84 bool runPendingHighPriorityTasksIfInCompositorPriority(); 86 bool runPendingHighPriorityTasksIfInCompositorPriority();
85 87
86 // Returns true if any work was done. 88 // Returns true if any work was done.
87 bool swapQueuesAndRunPendingTasks(); 89 bool swapQueuesAndRunPendingTasks();
88 90
89 void swapQueuesRunPendingTasksAndAllowHighPriorityTaskRunnerPosting(); 91 void swapQueuesRunPendingTasksAndAllowHighPriorityTaskRunnerPosting();
90 92
91 // Returns true if any work was done. 93 // Returns true if any work was done.
92 bool executeHighPriorityTasks(Deque<TracedTask>&); 94 bool executeHighPriorityTasks(Deque<OwnPtr<TracedTask> >&);
95
96 // Returns true if any work was done.
97 bool swapQueuesAndRunPendingIdleTasks();
98
99 // Returns true if any work was done.
100 bool executeIdleTasks(Deque<OwnPtr<TracedTask> >&);
101
102 // Reposts all the tasks in idleTasks onto the idle task queue.
103 void repostAllIdleTasks(Deque<OwnPtr<TracedTask> >&);
104
105 // Returns the time in seconds until the current frame deadline expires.
106 double getSecondsUntilFrameDeadline() const;
Sami 2014/09/24 14:00:40 nit: drop the |get|, it's cleaner
rmcilroy 2014/09/29 17:42:57 Done.
93 107
94 // Return the current SchedulerPolicy. 108 // Return the current SchedulerPolicy.
95 SchedulerPolicy schedulerPolicy() const; 109 SchedulerPolicy schedulerPolicy() const;
96 110
97 void maybeEnterNormalSchedulerPolicy(); 111 void maybeEnterNormalSchedulerPolicy();
98 112
99 // Must be called while m_pendingTasksMutex is locked. 113 // Must be called while m_pendingTasksMutex is locked.
100 void maybePostMainThreadPendingHighPriorityTaskRunner(); 114 void maybePostMainThreadPendingHighPriorityTaskRunner();
101 115
102 void tickSharedTimer(); 116 void tickSharedTimer();
103 117
104 void (*m_sharedTimerFunction)(); 118 void (*m_sharedTimerFunction)();
105 119
106 // End of main thread only members ------------------------------------- 120 // End of main thread only members -------------------------------------
107 121
108 bool hasPendingHighPriorityWork() const; 122 bool hasPendingHighPriorityWork() const;
109 123
110 void enterSchedulerPolicyLocked(SchedulerPolicy); 124 void enterSchedulerPolicyLocked(SchedulerPolicy);
111 125
112 void enterSchedulerPolicy(SchedulerPolicy); 126 void enterSchedulerPolicy(SchedulerPolicy);
113 127
114 static Scheduler* s_sharedScheduler; 128 static Scheduler* s_sharedScheduler;
115 129
116 WebThread* m_mainThread; 130 WebThread* m_mainThread;
117 131
118 // This mutex protects calls to the pending task queue, m_highPriorityTaskRu nnerPosted and 132 // This mutex protects calls to the pending task queue, m_highPriorityTaskRu nnerPosted and
119 // m_compositorPriorityPolicyEndTimeSeconds. 133 // m_compositorPriorityPolicyEndTimeSeconds.
120 Mutex m_pendingTasksMutex; 134 Mutex m_pendingTasksMutex;
121 DoubleBufferedDeque<TracedTask> m_pendingHighPriorityTasks; 135 DoubleBufferedDeque<OwnPtr<TracedTask> > m_pendingHighPriorityTasks;
Sami 2014/09/24 14:00:40 As of Nico's email to chromium-dev@ yesterday I th
rmcilroy 2014/09/29 17:42:57 Acknowledged.
136 DoubleBufferedDeque<OwnPtr<TracedTask> > m_pendingIdleTasks;
122 double m_compositorPriorityPolicyEndTimeSeconds; 137 double m_compositorPriorityPolicyEndTimeSeconds;
123 138
139 double m_currentFrameDeadlineSeconds;
140
124 // Declared volatile as it is atomically incremented. 141 // Declared volatile as it is atomically incremented.
125 volatile int m_highPriorityTaskCount; 142 volatile int m_highPriorityTaskCount;
126 143
127 bool m_highPriorityTaskRunnerPosted; 144 bool m_highPriorityTaskRunnerPosted;
128 145
129 // Don't access m_schedulerPolicy directly, use enterSchedulerPolicyLocked a nd SchedulerPolicy instead. 146 // Don't access m_schedulerPolicy directly, use enterSchedulerPolicyLocked a nd SchedulerPolicy instead.
130 volatile int m_schedulerPolicy; 147 volatile int m_schedulerPolicy;
131 }; 148 };
132 149
133 } // namespace blink 150 } // namespace blink
134 151
135 #endif // Scheduler_h 152 #endif // Scheduler_h
OLDNEW
« no previous file with comments | « no previous file | Source/platform/scheduler/Scheduler.cpp » ('j') | Source/platform/scheduler/Scheduler.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698