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

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

Issue 364873002: Introduce a basic Blink Scheduler (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Build fix for old gcc. Created 6 years, 5 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
(Empty)
1 /*
2 * Copyright (C) 2014 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
14 * its contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #include "config.h"
30 #include "platform/scheduler/Scheduler.h"
31
32 #include "platform/Task.h"
33 #include "platform/TraceEvent.h"
34 #include "public/platform/Platform.h"
35
36 namespace WebCore {
37
38 namespace {
39
40 class MainThreadTaskAdapter : public blink::WebThread::Task {
eseidel 2014/07/15 15:59:11 What is this for?
41 public:
42 explicit MainThreadTaskAdapter(const Scheduler::Task& task)
43 : m_task(task)
44 {
45 }
46
47 // WebThread::Task implementation.
48 virtual void run() OVERRIDE
49 {
50 TRACE_EVENT0("blink", "MainThreadTaskAdapter::run");
51 m_task();
52 }
53
54 private:
55 Scheduler::Task m_task;
56 };
57
58 }
59
60 Scheduler* Scheduler::s_currentScheduler = nullptr;
61
62 void Scheduler::initializeOnMainThread()
63 {
64 s_currentScheduler = new Scheduler();
65 }
66
67 void Scheduler::shutdown()
68 {
69 delete s_currentScheduler;
70 s_currentScheduler = nullptr;
71 }
72
73 Scheduler* Scheduler::current()
eseidel 2014/07/15 15:59:11 I believe this method is normally called 'shared'
Sami 2014/07/15 19:20:05 Done.
74 {
75 return s_currentScheduler;
76 }
77
78 Scheduler::Scheduler()
79 : m_mainThread(blink::Platform::current()->currentThread())
80 , m_sharedTimerFunction(nullptr)
81 {
82 }
83
84 Scheduler::~Scheduler()
85 {
86 }
87
88 void Scheduler::scheduleTask(const Task& task)
89 {
90 m_mainThread->postTask(new MainThreadTaskAdapter(task));
eseidel 2014/07/15 15:59:11 I see, you want to speak to the Scheduler in terms
Sami 2014/07/15 19:20:05 Right. It's a bit unfortunate we can't share the s
91 }
92
93 void Scheduler::postTask(const Task& task)
94 {
95 scheduleTask(task);
96 }
97
98 void Scheduler::postInputTask(const Task& task)
99 {
100 scheduleTask(task);
101 }
102
103 void Scheduler::postCompositorTask(const Task& task)
104 {
105 scheduleTask(task);
106 }
107
108 void Scheduler::tickSharedTimer()
109 {
110 TRACE_EVENT0("blink", "Scheduler::tickSharedTimer");
111 m_sharedTimerFunction();
112 }
113
114 void Scheduler::sharedTimerAdapter()
115 {
116 current()->tickSharedTimer();
117 }
118
119 void Scheduler::setSharedTimerFiredFunction(void (*function)())
120 {
121 m_sharedTimerFunction = function;
122 blink::Platform::current()->setSharedTimerFiredFunction(function ? &Schedule r::sharedTimerAdapter : nullptr);
123 }
124
125 void Scheduler::setSharedTimerFireInterval(double interval)
126 {
127 blink::Platform::current()->setSharedTimerFireInterval(interval);
128 }
129
130 void Scheduler::stopSharedTimer()
131 {
132 blink::Platform::current()->stopSharedTimer();
133 }
134
135 bool Scheduler::shouldYieldForHighPriorityWork()
136 {
137 return false;
138 }
139
140 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698