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

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

Issue 595023002: Implement idle task scheduling. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Post idle tasks to the main thread run loop. Created 6 years, 2 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
« no previous file with comments | « Source/platform/scheduler/Scheduler.h ('k') | Source/platform/scheduler/TracedTask.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "config.h" 5 #include "config.h"
6 #include "platform/scheduler/Scheduler.h" 6 #include "platform/scheduler/Scheduler.h"
7 7
8 #include "platform/PlatformThreadData.h" 8 #include "platform/PlatformThreadData.h"
9 #include "platform/Task.h" 9 #include "platform/Task.h"
10 #include "platform/ThreadTimers.h" 10 #include "platform/ThreadTimers.h"
11 #include "platform/TraceEvent.h" 11 #include "platform/TraceEvent.h"
12 #include "public/platform/Platform.h" 12 #include "public/platform/Platform.h"
13 #include "wtf/MainThread.h" 13 #include "wtf/MainThread.h"
14 14
15 namespace blink { 15 namespace blink {
16 16
17 namespace { 17 namespace {
18 18
19 // The time we should stay in CompositorPriority mode for, after a touch event. 19 // The time we should stay in CompositorPriority mode for, after a touch event.
20 double kLowSchedulerPolicyAfterTouchTimeSeconds = 0.1; 20 double kLowSchedulerPolicyAfterTouchTimeSeconds = 0.1;
21 21
22 // Can be created from any thread.
23 // Note if the scheduler gets shutdown, this may be run after.
24 class MainThreadIdleTaskAdapter : public WebThread::Task {
25 public:
26 MainThreadIdleTaskAdapter(const Scheduler::IdleTask& idleTask, double allott edTimeMs, const TraceLocation& location)
27 : m_idleTask(idleTask)
28 , m_allottedTimeMs(allottedTimeMs)
29 , m_location(location)
30 {
31 }
32
33 // WebThread::Task implementation.
34 virtual void run() OVERRIDE
35 {
36 TRACE_EVENT2("blink", "MainThreadIdleTaskAdapter::run",
37 "src_file", m_location.fileName(),
38 "src_func", m_location.functionName());
39 m_idleTask(m_allottedTimeMs);
40 }
41
42 private:
43 Scheduler::IdleTask m_idleTask;
44 double m_allottedTimeMs;
45 TraceLocation m_location;
46 };
47
48 } // namespace 22 } // namespace
49 23
50 // Typically only created from compositor or render threads. 24 // Typically only created from compositor or render threads.
51 // Note if the scheduler gets shutdown, this may be run after. 25 // Note if the scheduler gets shutdown, this may be run after.
52 class Scheduler::MainThreadPendingHighPriorityTaskRunner : public WebThread::Tas k { 26 class Scheduler::MainThreadPendingHighPriorityTaskRunner : public WebThread::Tas k {
53 public: 27 public:
54 MainThreadPendingHighPriorityTaskRunner() 28 MainThreadPendingHighPriorityTaskRunner()
55 { 29 {
56 ASSERT(Scheduler::shared()); 30 ASSERT(Scheduler::shared());
57 } 31 }
(...skipping 21 matching lines...) Expand all
79 const Scheduler::Task& task, const TraceLocation& location, const char* traceName) 53 const Scheduler::Task& task, const TraceLocation& location, const char* traceName)
80 : m_task(task, location, traceName) 54 : m_task(task, location, traceName)
81 { 55 {
82 ASSERT(Scheduler::shared()); 56 ASSERT(Scheduler::shared());
83 } 57 }
84 58
85 // WebThread::Task implementation. 59 // WebThread::Task implementation.
86 virtual void run() OVERRIDE 60 virtual void run() OVERRIDE
87 { 61 {
88 Scheduler* scheduler = Scheduler::shared(); 62 Scheduler* scheduler = Scheduler::shared();
89 // FIXME: This check should't be necessary, tasks should not outlive bli nk. 63 // FIXME: This check shouldn't be necessary, tasks should not outlive bl ink.
90 ASSERT(scheduler); 64 ASSERT(scheduler);
91 if (scheduler) 65 if (scheduler)
92 Scheduler::shared()->runPendingHighPriorityTasksIfInCompositorPriori ty(); 66 scheduler->runPendingHighPriorityTasksIfInCompositorPriority();
67
93 m_task.run(); 68 m_task.run();
94 } 69 }
95 70
96 TracedTask m_task; 71 private:
72 TracedStandardTask m_task;
97 }; 73 };
98 74
75
76 // Can be created from any thread.
77 // Note if the scheduler gets shutdown, this may be run after.
78 class Scheduler::MainThreadPendingIdleTaskRunner : public WebThread::Task {
79 public:
80 MainThreadPendingIdleTaskRunner(const TracedIdleTask& idleTask)
81 : m_idleTask(idleTask)
82 {
83 ASSERT(Scheduler::shared());
84 }
85
86 // WebThread::Task implementation.
87 virtual void run() OVERRIDE
88 {
89 Scheduler* scheduler = Scheduler::shared();
90 // FIXME: This check shouldn't be necessary, tasks should not outlive bl ink.
91 ASSERT(scheduler);
92 if (scheduler) {
93 scheduler->runPendingHighPriorityTasksIfInCompositorPriority();
94
95 if (scheduler->canRunIdleTask()) {
96 m_idleTask.run();
97 // Run the next idle task if possible.
98 scheduler->maybeExecuteIdleTask();
99 } else {
100 scheduler->repostIdleTask(m_idleTask);
101 }
102 }
103 }
104
105 private:
106 TracedIdleTask m_idleTask;
107 };
108
109
99 Scheduler* Scheduler::s_sharedScheduler = nullptr; 110 Scheduler* Scheduler::s_sharedScheduler = nullptr;
100 111
101 void Scheduler::initializeOnMainThread() 112 void Scheduler::initializeOnMainThread()
102 { 113 {
103 s_sharedScheduler = new Scheduler(); 114 s_sharedScheduler = new Scheduler();
104 } 115 }
105 116
106 void Scheduler::shutdown() 117 void Scheduler::shutdown()
107 { 118 {
108 delete s_sharedScheduler; 119 delete s_sharedScheduler;
109 s_sharedScheduler = nullptr; 120 s_sharedScheduler = nullptr;
110 } 121 }
111 122
112 Scheduler* Scheduler::shared() 123 Scheduler* Scheduler::shared()
113 { 124 {
114 return s_sharedScheduler; 125 return s_sharedScheduler;
115 } 126 }
116 127
117 Scheduler::Scheduler() 128 Scheduler::Scheduler()
118 : m_sharedTimerFunction(nullptr) 129 : m_sharedTimerFunction(nullptr)
119 , m_mainThread(blink::Platform::current()->currentThread()) 130 , m_mainThread(blink::Platform::current()->currentThread())
120 , m_compositorPriorityPolicyEndTimeSeconds(0) 131 , m_compositorPriorityPolicyEndTimeSeconds(0)
132 , m_currentFrameDeadlineSeconds(0)
121 , m_highPriorityTaskCount(0) 133 , m_highPriorityTaskCount(0)
122 , m_highPriorityTaskRunnerPosted(false) 134 , m_highPriorityTaskRunnerPosted(false)
123 , m_schedulerPolicy(Normal) 135 , m_schedulerPolicy(Normal)
124 { 136 {
125 } 137 }
126 138
127 Scheduler::~Scheduler() 139 Scheduler::~Scheduler()
128 { 140 {
129 while (hasPendingHighPriorityWork()) { 141 while (hasPendingHighPriorityWork()) {
130 swapQueuesAndRunPendingTasks(); 142 swapQueuesAndRunPendingTasks();
131 } 143 }
132 } 144 }
133 145
134 void Scheduler::willBeginFrame(const WebBeginFrameArgs& args) 146 void Scheduler::willBeginFrame(double frameDeadlineSeconds)
135 { 147 {
136 // TODO: Use frame deadline and interval to schedule idle tasks. 148 m_currentFrameCommitted = false;
149 m_currentFrameDeadlineSeconds = frameDeadlineSeconds;
150
151 // TODO: Schedule a deferred task here to run idle work if didCommitFrameToC ompositor never get's called
137 } 152 }
138 153
139 void Scheduler::didCommitFrameToCompositor() 154 void Scheduler::didCommitFrameToCompositor()
140 { 155 {
141 // TODO: Trigger the frame deadline immediately. 156 m_currentFrameCommitted = true;
142 } 157 maybeExecuteIdleTask();
143
144 void Scheduler::scheduleIdleTask(const TraceLocation& location, const IdleTask& idleTask)
145 {
146 // TODO: send a real allottedTime here.
147 m_mainThread->postTask(new MainThreadIdleTaskAdapter(idleTask, 0, location)) ;
148 } 158 }
149 159
150 void Scheduler::postHighPriorityTaskInternal(const TraceLocation& location, cons t Task& task, const char* traceName) 160 void Scheduler::postHighPriorityTaskInternal(const TraceLocation& location, cons t Task& task, const char* traceName)
151 { 161 {
152 Locker<Mutex> lock(m_pendingTasksMutex); 162 Locker<Mutex> lock(m_pendingTasksMutex);
153 163
154 m_pendingHighPriorityTasks.append(TracedTask(task, location, traceName)); 164 m_pendingHighPriorityTasks.append(TracedStandardTask(task, location, traceNa me));
155 atomicIncrement(&m_highPriorityTaskCount); 165 atomicIncrement(&m_highPriorityTaskCount);
156 maybePostMainThreadPendingHighPriorityTaskRunner(); 166 maybePostMainThreadPendingHighPriorityTaskRunner();
157 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("blink.scheduler"), "PendingHighPri orityTasks", m_highPriorityTaskCount); 167 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("blink.scheduler"), "PendingHighPri orityTasks", m_highPriorityTaskCount);
158 } 168 }
159 169
170 void Scheduler::postIdleTaskInternal(const TraceLocation& location, const IdleTa sk& idleTask, const char* traceName)
171 {
172 Locker<Mutex> lock(m_pendingTasksMutex);
173 m_pendingIdleTasks.append(TracedIdleTask(idleTask, location, traceName));
174 }
175
160 void Scheduler::postTask(const TraceLocation& location, const Task& task) 176 void Scheduler::postTask(const TraceLocation& location, const Task& task)
161 { 177 {
162 m_mainThread->postTask(new MainThreadPendingTaskRunner(task, location, "Sche duler::MainThreadTask")); 178 m_mainThread->postTask(new MainThreadPendingTaskRunner(task, location, "Sche duler::MainThreadTask"));
163 } 179 }
164 180
165 void Scheduler::postInputTask(const TraceLocation& location, const Task& task) 181 void Scheduler::postInputTask(const TraceLocation& location, const Task& task)
166 { 182 {
167 postHighPriorityTaskInternal(location, task, "Scheduler::InputTask"); 183 postHighPriorityTaskInternal(location, task, "Scheduler::InputTask");
168 } 184 }
169 185
170 void Scheduler::didReceiveInputEvent() 186 void Scheduler::didReceiveInputEvent()
171 { 187 {
172 enterSchedulerPolicy(CompositorPriority); 188 enterSchedulerPolicy(CompositorPriority);
173 } 189 }
174 190
175 void Scheduler::postCompositorTask(const TraceLocation& location, const Task& ta sk) 191 void Scheduler::postCompositorTask(const TraceLocation& location, const Task& ta sk)
176 { 192 {
177 postHighPriorityTaskInternal(location, task, "Scheduler::CompositorTask"); 193 postHighPriorityTaskInternal(location, task, "Scheduler::CompositorTask");
178 } 194 }
179 195
180 void Scheduler::postIpcTask(const TraceLocation& location, const Task& task) 196 void Scheduler::postIpcTask(const TraceLocation& location, const Task& task)
181 { 197 {
182 // FIXME: we want IPCs to be high priority, but we can't currently do that b ecause some of them can take a very long 198 // FIXME: we want IPCs to be high priority, but we can't currently do that b ecause some of them can take a very long
183 // time to process. These need refactoring but we need to add some infrastru cture to identify them. 199 // time to process. These need refactoring but we need to add some infrastru cture to identify them.
184 m_mainThread->postTask(new MainThreadPendingTaskRunner(task, location, "Sche duler::IpcTask")); 200 m_mainThread->postTask(new MainThreadPendingTaskRunner(task, location, "Sche duler::IpcTask"));
185 } 201 }
186 202
203 void Scheduler::postIdleTask(const TraceLocation& location, const IdleTask& idle Task)
204 {
205 postIdleTaskInternal(location, idleTask, "Scheduler::IdleTask");
206 }
207
187 void Scheduler::maybePostMainThreadPendingHighPriorityTaskRunner() 208 void Scheduler::maybePostMainThreadPendingHighPriorityTaskRunner()
188 { 209 {
189 ASSERT(m_pendingTasksMutex.locked()); 210 ASSERT(m_pendingTasksMutex.locked());
190 if (m_highPriorityTaskRunnerPosted) 211 if (m_highPriorityTaskRunnerPosted)
191 return; 212 return;
192 m_mainThread->postTask(new MainThreadPendingHighPriorityTaskRunner()); 213 m_mainThread->postTask(new MainThreadPendingHighPriorityTaskRunner());
193 m_highPriorityTaskRunnerPosted = true; 214 m_highPriorityTaskRunnerPosted = true;
194 } 215 }
195 216
196 void Scheduler::postIdleTask(const TraceLocation& location, const IdleTask& idle Task)
197 {
198 scheduleIdleTask(location, idleTask);
199 }
200 217
201 void Scheduler::tickSharedTimer() 218 void Scheduler::tickSharedTimer()
202 { 219 {
203 TRACE_EVENT0("blink", "Scheduler::tickSharedTimer"); 220 TRACE_EVENT0("blink", "Scheduler::tickSharedTimer");
204 221
205 // Run any high priority tasks that are queued up, otherwise the blink timer s will yield immediately. 222 // Run any high priority tasks that are queued up, otherwise the blink timer s will yield immediately.
206 bool workDone = runPendingHighPriorityTasksIfInCompositorPriority(); 223 bool workDone = runPendingHighPriorityTasksIfInCompositorPriority();
207 m_sharedTimerFunction(); 224 m_sharedTimerFunction();
208 225
209 // The blink timers may have just yielded, so run any high priority tasks th at where queued up 226 // The blink timers may have just yielded, so run any high priority tasks th at where queued up
(...skipping 11 matching lines...) Expand all
221 return swapQueuesAndRunPendingTasks(); 238 return swapQueuesAndRunPendingTasks();
222 } 239 }
223 240
224 bool Scheduler::swapQueuesAndRunPendingTasks() 241 bool Scheduler::swapQueuesAndRunPendingTasks()
225 { 242 {
226 ASSERT(isMainThread()); 243 ASSERT(isMainThread());
227 244
228 // These locks guard against another thread posting input or compositor task s while we swap the buffers. 245 // These locks guard against another thread posting input or compositor task s while we swap the buffers.
229 // One the buffers have been swapped we can safely access the returned deque without having to lock. 246 // One the buffers have been swapped we can safely access the returned deque without having to lock.
230 m_pendingTasksMutex.lock(); 247 m_pendingTasksMutex.lock();
231 Deque<TracedTask>& highPriorityTasks = m_pendingHighPriorityTasks.swapBuffer s(); 248 Deque<TracedStandardTask>& highPriorityTasks = m_pendingHighPriorityTasks.sw apBuffers();
232 maybeEnterNormalSchedulerPolicy(); 249 maybeEnterNormalSchedulerPolicy();
233 m_pendingTasksMutex.unlock(); 250 m_pendingTasksMutex.unlock();
234 return executeHighPriorityTasks(highPriorityTasks); 251 return executeHighPriorityTasks(highPriorityTasks);
235 } 252 }
236 253
237 void Scheduler::swapQueuesRunPendingTasksAndAllowHighPriorityTaskRunnerPosting() 254 void Scheduler::swapQueuesRunPendingTasksAndAllowHighPriorityTaskRunnerPosting()
238 { 255 {
239 ASSERT(isMainThread()); 256 ASSERT(isMainThread());
240 257
241 // These locks guard against another thread posting input or compositor task s while we swap the buffers. 258 // These locks guard against another thread posting input or compositor task s while we swap the buffers.
242 // One the buffers have been swapped we can safely access the returned deque without having to lock. 259 // One the buffers have been swapped we can safely access the returned deque without having to lock.
243 m_pendingTasksMutex.lock(); 260 m_pendingTasksMutex.lock();
244 Deque<TracedTask>& highPriorityTasks = m_pendingHighPriorityTasks.swapBuffer s(); 261 Deque<TracedStandardTask>& highPriorityTasks = m_pendingHighPriorityTasks.sw apBuffers();
245 m_highPriorityTaskRunnerPosted = false; 262 m_highPriorityTaskRunnerPosted = false;
246 maybeEnterNormalSchedulerPolicy(); 263 maybeEnterNormalSchedulerPolicy();
247 m_pendingTasksMutex.unlock(); 264 m_pendingTasksMutex.unlock();
248 executeHighPriorityTasks(highPriorityTasks); 265 executeHighPriorityTasks(highPriorityTasks);
249 } 266 }
250 267
251 void Scheduler::maybeEnterNormalSchedulerPolicy() 268 void Scheduler::maybeEnterNormalSchedulerPolicy()
252 { 269 {
253 ASSERT(isMainThread()); 270 ASSERT(isMainThread());
254 ASSERT(m_pendingTasksMutex.locked()); 271 ASSERT(m_pendingTasksMutex.locked());
255 272
256 // Go back to the normal scheduler policy if enough time has elapsed. 273 // Go back to the normal scheduler policy if enough time has elapsed.
257 if (schedulerPolicy() == CompositorPriority && Platform::current()->monotoni callyIncreasingTime() > m_compositorPriorityPolicyEndTimeSeconds) 274 if (schedulerPolicy() == CompositorPriority && Platform::current()->monotoni callyIncreasingTime() > m_compositorPriorityPolicyEndTimeSeconds)
258 enterSchedulerPolicyLocked(Normal); 275 enterSchedulerPolicyLocked(Normal);
259 } 276 }
260 277
261 bool Scheduler::executeHighPriorityTasks(Deque<TracedTask>& highPriorityTasks) 278 bool Scheduler::executeHighPriorityTasks(Deque<TracedStandardTask>& highPriority Tasks)
262 { 279 {
263 TRACE_EVENT0("blink", "Scheduler::executeHighPriorityTasks"); 280 TRACE_EVENT0("blink", "Scheduler::executeHighPriorityTasks");
264 int highPriorityTasksExecuted = 0; 281 int highPriorityTasksExecuted = 0;
265 while (!highPriorityTasks.isEmpty()) { 282 while (!highPriorityTasks.isEmpty()) {
266 highPriorityTasks.takeFirst().run(); 283 highPriorityTasks.takeFirst().run();
267 highPriorityTasksExecuted++; 284 highPriorityTasksExecuted++;
268 } 285 }
269 286
270 int highPriorityTaskCount = atomicSubtract(&m_highPriorityTaskCount, highPri orityTasksExecuted); 287 int highPriorityTaskCount = atomicSubtract(&m_highPriorityTaskCount, highPri orityTasksExecuted);
271 ASSERT_UNUSED(highPriorityTaskCount, highPriorityTaskCount >= 0); 288 ASSERT_UNUSED(highPriorityTaskCount, highPriorityTaskCount >= 0);
272 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("blink.scheduler"), "PendingHighPri orityTasks", m_highPriorityTaskCount); 289 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("blink.scheduler"), "PendingHighPri orityTasks", m_highPriorityTaskCount);
273 return highPriorityTasksExecuted > 0; 290 return highPriorityTasksExecuted > 0;
274 } 291 }
275 292
293 bool Scheduler::maybeExecuteIdleTask()
294 {
295 TRACE_EVENT0("blink", "Scheduler::maybeExecuteIdleTask");
296 if (canRunIdleTask()) {
297 Locker<Mutex> lock(m_pendingTasksMutex);
298 if (!m_pendingIdleTasks.isEmpty()) {
299 m_mainThread->postTask(new MainThreadPendingIdleTaskRunner(m_pending IdleTasks.takeFirst()));
300 return true;
301 }
302 }
picksi1 2014/09/30 09:13:51 Is this function correctly named? It isn't actuall
rmcilroy 2014/09/30 09:56:19 Yes it's tricky to name - I originally had maybeSc
picksi1 2014/09/30 12:34:00 maybePostMainThreadPendingHighPriorityTaskRunner()
303 return false;
304 }
305
306 void Scheduler::repostIdleTask(const TracedIdleTask& idleTask)
307 {
308 Locker<Mutex> lock(m_pendingTasksMutex);
309 // Post at the front since the task didn't get a chance to run.
310 m_pendingIdleTasks.prepend(idleTask);
311 }
312
picksi1 2014/09/30 09:13:51 Should this be called repostAtFront (etc) or somet
rmcilroy 2014/09/30 09:56:19 Done.
276 void Scheduler::sharedTimerAdapter() 313 void Scheduler::sharedTimerAdapter()
277 { 314 {
278 shared()->tickSharedTimer(); 315 shared()->tickSharedTimer();
279 } 316 }
280 317
281 void Scheduler::setSharedTimerFiredFunction(void (*function)()) 318 void Scheduler::setSharedTimerFiredFunction(void (*function)())
282 { 319 {
283 m_sharedTimerFunction = function; 320 m_sharedTimerFunction = function;
284 blink::Platform::current()->setSharedTimerFiredFunction(function ? &Schedule r::sharedTimerAdapter : nullptr); 321 blink::Platform::current()->setSharedTimerFiredFunction(function ? &Schedule r::sharedTimerAdapter : nullptr);
285 } 322 }
(...skipping 20 matching lines...) Expand all
306 bool Scheduler::hasPendingHighPriorityWork() const 343 bool Scheduler::hasPendingHighPriorityWork() const
307 { 344 {
308 // This method is expected to be run on the main thread, but the high priori ty tasks will be posted by 345 // This method is expected to be run on the main thread, but the high priori ty tasks will be posted by
309 // other threads. We could use locks here, but this function is (sometimes) called a lot by 346 // other threads. We could use locks here, but this function is (sometimes) called a lot by
310 // ThreadTimers::sharedTimerFiredInternal so we decided to use atomics + bar rier loads here which 347 // ThreadTimers::sharedTimerFiredInternal so we decided to use atomics + bar rier loads here which
311 // should be cheaper. 348 // should be cheaper.
312 // NOTE it's possible the barrier read is overkill here, since delayed yield ing isn't a big deal. 349 // NOTE it's possible the barrier read is overkill here, since delayed yield ing isn't a big deal.
313 return acquireLoad(&m_highPriorityTaskCount) != 0; 350 return acquireLoad(&m_highPriorityTaskCount) != 0;
314 } 351 }
315 352
353 double Scheduler::currentFrameDeadlineSeconds() const
354 {
355 return m_currentFrameDeadlineSeconds;
356 }
357
358 bool Scheduler::canRunIdleTask() const
359 {
360 return m_currentFrameCommitted && (m_currentFrameDeadlineSeconds > Platform: :current()->monotonicallyIncreasingTime());
361 }
362
316 Scheduler::SchedulerPolicy Scheduler::schedulerPolicy() const 363 Scheduler::SchedulerPolicy Scheduler::schedulerPolicy() const
317 { 364 {
318 ASSERT(isMainThread()); 365 ASSERT(isMainThread());
319 // It's important not to miss the transition from normal to low latency mode , otherwise we're likely to 366 // It's important not to miss the transition from normal to low latency mode , otherwise we're likely to
320 // delay the processing of input tasks. Since that transition is triggered b y a different thread, we 367 // delay the processing of input tasks. Since that transition is triggered b y a different thread, we
321 // need either a lock or a memory barrier, and the memory barrier is probabl y cheaper. 368 // need either a lock or a memory barrier, and the memory barrier is probabl y cheaper.
322 return static_cast<SchedulerPolicy>(acquireLoad(&m_schedulerPolicy)); 369 return static_cast<SchedulerPolicy>(acquireLoad(&m_schedulerPolicy));
323 } 370 }
324 371
325 void Scheduler::enterSchedulerPolicy(SchedulerPolicy schedulerPolicy) 372 void Scheduler::enterSchedulerPolicy(SchedulerPolicy schedulerPolicy)
326 { 373 {
327 Locker<Mutex> lock(m_pendingTasksMutex); 374 Locker<Mutex> lock(m_pendingTasksMutex);
328 enterSchedulerPolicyLocked(schedulerPolicy); 375 enterSchedulerPolicyLocked(schedulerPolicy);
329 } 376 }
330 377
331 void Scheduler::enterSchedulerPolicyLocked(SchedulerPolicy schedulerPolicy) 378 void Scheduler::enterSchedulerPolicyLocked(SchedulerPolicy schedulerPolicy)
332 { 379 {
333 ASSERT(m_pendingTasksMutex.locked()); 380 ASSERT(m_pendingTasksMutex.locked());
334 if (schedulerPolicy == CompositorPriority) 381 if (schedulerPolicy == CompositorPriority)
335 m_compositorPriorityPolicyEndTimeSeconds = Platform::current()->monotoni callyIncreasingTime() + kLowSchedulerPolicyAfterTouchTimeSeconds; 382 m_compositorPriorityPolicyEndTimeSeconds = Platform::current()->monotoni callyIncreasingTime() + kLowSchedulerPolicyAfterTouchTimeSeconds;
336 383
337 releaseStore(&m_schedulerPolicy, schedulerPolicy); 384 releaseStore(&m_schedulerPolicy, schedulerPolicy);
338 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("blink.scheduler"), "SchedulerPolic y", schedulerPolicy); 385 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("blink.scheduler"), "SchedulerPolic y", schedulerPolicy);
339 } 386 }
340 387
341 } // namespace blink 388 } // namespace blink
OLDNEW
« no previous file with comments | « Source/platform/scheduler/Scheduler.h ('k') | Source/platform/scheduler/TracedTask.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698