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

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: Cleaned up includes + build fix. 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
« no previous file with comments | « Source/platform/scheduler/Scheduler.h ('k') | Source/platform/scheduler/SchedulerTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "config.h"
6 #include "platform/scheduler/Scheduler.h"
7
8 #include "platform/Task.h"
9 #include "platform/TraceEvent.h"
10 #include "public/platform/Platform.h"
11 #include "public/platform/WebThread.h"
12
13 namespace WebCore {
14
15 namespace {
16
17 class MainThreadTaskAdapter : public blink::WebThread::Task {
18 public:
19 explicit MainThreadTaskAdapter(const Scheduler::Task& task)
20 : m_task(task)
21 {
22 }
23
24 // WebThread::Task implementation.
25 virtual void run() OVERRIDE
26 {
27 TRACE_EVENT0("blink", "MainThreadTaskAdapter::run");
28 m_task();
29 }
30
31 private:
32 Scheduler::Task m_task;
33 };
34
35 }
36
37 Scheduler* Scheduler::s_sharedScheduler = nullptr;
38
39 void Scheduler::initializeOnMainThread()
40 {
41 s_sharedScheduler = new Scheduler();
picksi1 2014/08/01 10:36:12 nit: Is it worth checking that s_sharedScheduler i
42 }
43
44 void Scheduler::shutdown()
45 {
46 delete s_sharedScheduler;
47 s_sharedScheduler = nullptr;
48 }
49
50 Scheduler* Scheduler::shared()
51 {
52 return s_sharedScheduler;
53 }
54
55 Scheduler::Scheduler()
56 : m_mainThread(blink::Platform::current()->currentThread())
57 , m_sharedTimerFunction(nullptr)
58 {
59 }
60
61 Scheduler::~Scheduler()
62 {
63 }
64
65 void Scheduler::scheduleTask(const Task& task)
66 {
67 m_mainThread->postTask(new MainThreadTaskAdapter(task));
68 }
69
70 void Scheduler::postTask(const Task& task)
71 {
72 scheduleTask(task);
73 }
74
75 void Scheduler::postInputTask(const Task& task)
76 {
77 scheduleTask(task);
78 }
79
80 void Scheduler::postCompositorTask(const Task& task)
81 {
82 scheduleTask(task);
83 }
84
85 void Scheduler::tickSharedTimer()
86 {
87 TRACE_EVENT0("blink", "Scheduler::tickSharedTimer");
88 m_sharedTimerFunction();
89 }
90
91 void Scheduler::sharedTimerAdapter()
92 {
93 shared()->tickSharedTimer();
94 }
95
96 void Scheduler::setSharedTimerFiredFunction(void (*function)())
97 {
98 m_sharedTimerFunction = function;
99 blink::Platform::current()->setSharedTimerFiredFunction(function ? &Schedule r::sharedTimerAdapter : nullptr);
100 }
101
102 void Scheduler::setSharedTimerFireInterval(double interval)
103 {
104 blink::Platform::current()->setSharedTimerFireInterval(interval);
105 }
106
107 void Scheduler::stopSharedTimer()
108 {
109 blink::Platform::current()->stopSharedTimer();
110 }
111
112 bool Scheduler::shouldYieldForHighPriorityWork()
113 {
114 return false;
115 }
116
117 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/platform/scheduler/Scheduler.h ('k') | Source/platform/scheduler/SchedulerTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698