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

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

Issue 559973003: Adds the concept of Policies to the Blink Scheduler (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Change the test time funcstions to be non-static 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
« no previous file with comments | « no previous file | Source/platform/scheduler/Scheduler.cpp » ('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 #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/TraceLocation.h"
10 #include "wtf/DoubleBufferedDeque.h" 10 #include "wtf/DoubleBufferedDeque.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 // and the caller should yield to let the scheduler service that work. 47 // and the caller should yield to let the scheduler service that work.
48 // Can be called on any thread. 48 // Can be called on any thread.
49 bool shouldYieldForHighPriorityWork() const; 49 bool shouldYieldForHighPriorityWork() const;
50 50
51 // The shared timer can be used to schedule a periodic callback which may 51 // The shared timer can be used to schedule a periodic callback which may
52 // get preempted by higher priority work. 52 // get preempted by higher priority work.
53 void setSharedTimerFiredFunction(void (*function)()); 53 void setSharedTimerFiredFunction(void (*function)());
54 void setSharedTimerFireInterval(double); 54 void setSharedTimerFireInterval(double);
55 void stopSharedTimer(); 55 void stopSharedTimer();
56 56
57 private: 57 protected:
58 class MainThreadPendingTaskRunner; 58 class MainThreadPendingTaskRunner;
59 class MainThreadPendingHighPriorityTaskRunner; 59 class MainThreadPendingHighPriorityTaskRunner;
60 friend class MainThreadPendingTaskRunner; 60 friend class MainThreadPendingTaskRunner;
61 friend class MainThreadPendingHighPriorityTaskRunner; 61 friend class MainThreadPendingHighPriorityTaskRunner;
62 62
63 enum SchedulerPolicy {
64 Normal,
65 CompositorPriority,
66 };
67
63 class TracedTask { 68 class TracedTask {
64 public: 69 public:
65 TracedTask(const Task& task, const TraceLocation& location) 70 TracedTask(const Task& task, const TraceLocation& location)
66 : m_task(task) 71 : m_task(task)
67 , m_location(location) { } 72 , m_location(location) { }
68 73
69 void run(); 74 void run();
70 75
71 private: 76 private:
72 Task m_task; 77 Task m_task;
73 TraceLocation m_location; 78 TraceLocation m_location;
74 }; 79 };
75 80
76 Scheduler(); 81 Scheduler();
77 ~Scheduler(); 82 virtual ~Scheduler();
78
79 void scheduleIdleTask(const TraceLocation&, const IdleTask&);
80 83
81 static void sharedTimerAdapter(); 84 static void sharedTimerAdapter();
82 void tickSharedTimer();
83 85
84 bool hasPendingHighPriorityWork() const; 86
87 // Start of main thread only members -----------------------------------
88
89 // Only does work in CompositorPriority mode. Returns true if any work was d one.
90 bool runPendingHighPriorityTasksIfInCompositorPriority();
91
92 // Returns true if any work was done.
85 bool swapQueuesAndRunPendingTasks(); 93 bool swapQueuesAndRunPendingTasks();
94
86 void swapQueuesRunPendingTasksAndAllowHighPriorityTaskRunnerPosting(); 95 void swapQueuesRunPendingTasksAndAllowHighPriorityTaskRunnerPosting();
87 96
88 // Returns true if any work was done. 97 // Returns true if any work was done.
89 bool executeHighPriorityTasks(Deque<TracedTask>&); 98 bool executeHighPriorityTasks(Deque<TracedTask>&);
90 99
100 // Return the current SchedulerPolicy.
101 SchedulerPolicy schedulerPolicy() const;
102
103 void maybeEnterNormalSchedulerPolicy();
104
91 // Must be called while m_pendingTasksMutex is locked. 105 // Must be called while m_pendingTasksMutex is locked.
92 void maybePostMainThreadPendingHighPriorityTaskRunner(); 106 void maybePostMainThreadPendingHighPriorityTaskRunner();
93 107
108 void tickSharedTimer();
109
110 void (*m_sharedTimerFunction)();
111
112 // End of main thread only members -------------------------------------
113
114
115 void scheduleIdleTask(const TraceLocation&, const IdleTask&);
116
117 bool hasPendingHighPriorityWork() const;
118
119 void enterSchedulerPolicyLocked(SchedulerPolicy);
120
121 void enterSchedulerPolicy(SchedulerPolicy);
122
94 static Scheduler* s_sharedScheduler; 123 static Scheduler* s_sharedScheduler;
95 124
96 // Should only be accessed from the main thread.
97 void (*m_sharedTimerFunction)();
98
99 // These members can be accessed from any thread.
100 WebThread* m_mainThread; 125 WebThread* m_mainThread;
101 126
102 // This mutex protects calls to the pending task queue and m_highPriorityTas kRunnerPosted. 127 // This mutex protects calls to the pending task queue, m_highPriorityTaskRu nnerPosted and
128 // m_compositorPriorityPolicyEndTimeSeconds.
103 Mutex m_pendingTasksMutex; 129 Mutex m_pendingTasksMutex;
104 DoubleBufferedDeque<TracedTask> m_pendingHighPriorityTasks; 130 DoubleBufferedDeque<TracedTask> m_pendingHighPriorityTasks;
131 double m_compositorPriorityPolicyEndTimeSeconds;
105 132
106 volatile int m_highPriorityTaskCount; 133 volatile int m_highPriorityTaskCount;
107 bool m_highPriorityTaskRunnerPosted; 134 bool m_highPriorityTaskRunnerPosted;
135
136 // Don't access m_schedulerPolicy directly, use enterSchedulerPolicyLocked a nd SchedulerPolicy instead.
137 volatile int m_schedulerPolicy;
108 }; 138 };
109 139
110 } // namespace blink 140 } // namespace blink
111 141
112 #endif // Scheduler_h 142 #endif // Scheduler_h
OLDNEW
« no previous file with comments | « no previous file | Source/platform/scheduler/Scheduler.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698