Chromium Code Reviews| Index: Source/platform/scheduler/Scheduler.cpp |
| diff --git a/Source/platform/scheduler/Scheduler.cpp b/Source/platform/scheduler/Scheduler.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f2646af6cee927dffbfef1a93bfd8b1acc7965d5 |
| --- /dev/null |
| +++ b/Source/platform/scheduler/Scheduler.cpp |
| @@ -0,0 +1,140 @@ |
| +/* |
| + * Copyright (C) 2014 Google Inc. All rights reserved. |
| + * |
| + * Redistribution and use in source and binary forms, with or without |
| + * modification, are permitted provided that the following conditions |
| + * are met: |
| + * |
| + * 1. Redistributions of source code must retain the above copyright |
| + * notice, this list of conditions and the following disclaimer. |
| + * 2. Redistributions in binary form must reproduce the above copyright |
| + * notice, this list of conditions and the following disclaimer in the |
| + * documentation and/or other materials provided with the distribution. |
| + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of |
| + * its contributors may be used to endorse or promote products derived |
| + * from this software without specific prior written permission. |
| + * |
| + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY |
| + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
| + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| + */ |
| + |
| +#include "config.h" |
| +#include "platform/scheduler/Scheduler.h" |
| + |
| +#include "platform/Task.h" |
| +#include "platform/TraceEvent.h" |
| +#include "public/platform/Platform.h" |
| + |
| +namespace WebCore { |
| + |
| +namespace { |
| + |
| +class MainThreadTaskAdapter : public blink::WebThread::Task { |
|
eseidel
2014/07/15 15:59:11
What is this for?
|
| +public: |
| + explicit MainThreadTaskAdapter(const Scheduler::Task& task) |
| + : m_task(task) |
| + { |
| + } |
| + |
| + // WebThread::Task implementation. |
| + virtual void run() OVERRIDE |
| + { |
| + TRACE_EVENT0("blink", "MainThreadTaskAdapter::run"); |
| + m_task(); |
| + } |
| + |
| +private: |
| + Scheduler::Task m_task; |
| +}; |
| + |
| +} |
| + |
| +Scheduler* Scheduler::s_currentScheduler = nullptr; |
| + |
| +void Scheduler::initializeOnMainThread() |
| +{ |
| + s_currentScheduler = new Scheduler(); |
| +} |
| + |
| +void Scheduler::shutdown() |
| +{ |
| + delete s_currentScheduler; |
| + s_currentScheduler = nullptr; |
| +} |
| + |
| +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.
|
| +{ |
| + return s_currentScheduler; |
| +} |
| + |
| +Scheduler::Scheduler() |
| + : m_mainThread(blink::Platform::current()->currentThread()) |
| + , m_sharedTimerFunction(nullptr) |
| +{ |
| +} |
| + |
| +Scheduler::~Scheduler() |
| +{ |
| +} |
| + |
| +void Scheduler::scheduleTask(const Task& task) |
| +{ |
| + 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
|
| +} |
| + |
| +void Scheduler::postTask(const Task& task) |
| +{ |
| + scheduleTask(task); |
| +} |
| + |
| +void Scheduler::postInputTask(const Task& task) |
| +{ |
| + scheduleTask(task); |
| +} |
| + |
| +void Scheduler::postCompositorTask(const Task& task) |
| +{ |
| + scheduleTask(task); |
| +} |
| + |
| +void Scheduler::tickSharedTimer() |
| +{ |
| + TRACE_EVENT0("blink", "Scheduler::tickSharedTimer"); |
| + m_sharedTimerFunction(); |
| +} |
| + |
| +void Scheduler::sharedTimerAdapter() |
| +{ |
| + current()->tickSharedTimer(); |
| +} |
| + |
| +void Scheduler::setSharedTimerFiredFunction(void (*function)()) |
| +{ |
| + m_sharedTimerFunction = function; |
| + blink::Platform::current()->setSharedTimerFiredFunction(function ? &Scheduler::sharedTimerAdapter : nullptr); |
| +} |
| + |
| +void Scheduler::setSharedTimerFireInterval(double interval) |
| +{ |
| + blink::Platform::current()->setSharedTimerFireInterval(interval); |
| +} |
| + |
| +void Scheduler::stopSharedTimer() |
| +{ |
| + blink::Platform::current()->stopSharedTimer(); |
| +} |
| + |
| +bool Scheduler::shouldYieldForHighPriorityWork() |
| +{ |
| + return false; |
| +} |
| + |
| +} // namespace WebCore |