Chromium Code Reviews

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

Issue 439923006: Prioritizing input and compositor tasks in the blink scheduler. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Responding to Sami's comments Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
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/TraceLocation.h"
10 #include "platform/scheduler/DoubleBufferedDeque.h"
9 #include "wtf/Functional.h" 11 #include "wtf/Functional.h"
10 #include "wtf/Noncopyable.h" 12 #include "wtf/Noncopyable.h"
13 #include "wtf/ThreadingPrimitives.h"
11 14
12 namespace blink { 15 namespace blink {
13 class WebThread; 16 class WebThread;
14 } 17 }
15 18
16 namespace blink { 19 namespace blink {
17 20
18 class TraceLocation; 21 class TraceLocation;
19 22
20 // The scheduler is an opinionated gateway for arranging work to be run on the 23 // The scheduler is an opinionated gateway for arranging work to be run on the
(...skipping 12 matching lines...)
33 36
34 // The following entrypoints are used to schedule different types of tasks 37 // The following entrypoints are used to schedule different types of tasks
35 // to be run on the main thread. They can be called from any thread. 38 // to be run on the main thread. They can be called from any thread.
36 void postInputTask(const TraceLocation&, const Task&); 39 void postInputTask(const TraceLocation&, const Task&);
37 void postCompositorTask(const TraceLocation&, const Task&); 40 void postCompositorTask(const TraceLocation&, const Task&);
38 void postTask(const TraceLocation&, const Task&); // For generic (low priori ty) tasks. 41 void postTask(const TraceLocation&, const Task&); // For generic (low priori ty) tasks.
39 void postIdleTask(const IdleTask&); // For non-critical tasks which may be r eordered relative to other task types. 42 void postIdleTask(const IdleTask&); // For non-critical tasks which may be r eordered relative to other task types.
40 43
41 // Returns true if there is high priority work pending on the main thread 44 // Returns true if there is high priority work pending on the main thread
42 // and the caller should yield to let the scheduler service that work. 45 // and the caller should yield to let the scheduler service that work.
43 // Can be called on the main thread. 46 // Can be called on any thread.
44 bool shouldYieldForHighPriorityWork(); 47 bool shouldYieldForHighPriorityWork();
45 48
46 // The shared timer can be used to schedule a periodic callback which may 49 // The shared timer can be used to schedule a periodic callback which may
47 // get preempted by higher priority work. 50 // get preempted by higher priority work.
48 void setSharedTimerFiredFunction(void (*function)()); 51 void setSharedTimerFiredFunction(void (*function)());
49 void setSharedTimerFireInterval(double); 52 void setSharedTimerFireInterval(double);
50 void stopSharedTimer(); 53 void stopSharedTimer();
51 54
52 private: 55 private:
56 class MainThreadPendingTaskRunner;
eseidel 2014/08/08 17:31:07 Do you need these forward declarations in order to
alexclarke 2014/08/12 11:37:02 gcc requires this sadly.
57 class MainThreadPendingHighPriorityTaskRunner;
58 friend class MainThreadPendingTaskRunner;
59 friend class MainThreadPendingHighPriorityTaskRunner;
60
53 Scheduler(); 61 Scheduler();
54 ~Scheduler(); 62 ~Scheduler();
55 63
56 void scheduleTask(const TraceLocation&, const Task&);
57 void scheduleIdleTask(const IdleTask&); 64 void scheduleIdleTask(const IdleTask&);
58 65
59 static void sharedTimerAdapter(); 66 static void sharedTimerAdapter();
60 void tickSharedTimer(); 67 void tickSharedTimer();
61 68
62 static Scheduler* s_sharedScheduler; 69 static Scheduler* s_sharedScheduler;
70
71 class TracedTask {
eseidel 2014/08/08 17:31:07 How is this different from Task? Can all Tasks's
alexclarke 2014/08/12 11:37:02 Done.
72 public:
73 TracedTask(const Task& task, const TraceLocation& location)
74 : m_task(task)
75 , m_location(location) { }
76
77 void run();
78
79 private:
80 Task m_task;
81 TraceLocation m_location;
82 };
83
84 void maybePostMainThreadPendingHighPriorityTaskRunner();
85 void runHighPriorityTasks();
86
87 // These members can be accessed from any thread.
63 blink::WebThread* m_mainThread; 88 blink::WebThread* m_mainThread;
eseidel 2014/08/08 17:31:07 You shouldn't need blink:: here.
alexclarke 2014/08/12 11:37:02 Done.
64 89 DoubleBufferedDeque<TracedTask> m_pendingInputTasks;
90 DoubleBufferedDeque<TracedTask> m_pendingCompositorTasks;
65 void (*m_sharedTimerFunction)(); 91 void (*m_sharedTimerFunction)();
92 volatile int m_mainThreadTaskRunnerCount;
66 }; 93 };
67 94
68 } // namespace blink 95 } // namespace blink
69 96
70 #endif // Scheduler_h 97 #endif // Scheduler_h
OLDNEW

Powered by Google App Engine