Chromium Code Reviews| Index: Source/platform/scheduler/Scheduler.h |
| diff --git a/Source/platform/scheduler/Scheduler.h b/Source/platform/scheduler/Scheduler.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b07e27a54c85795d8f149a060a8efa1eb46b35ed |
| --- /dev/null |
| +++ b/Source/platform/scheduler/Scheduler.h |
| @@ -0,0 +1,63 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef Scheduler_h |
| +#define Scheduler_h |
| + |
| +#include "platform/PlatformExport.h" |
| +#include "public/platform/WebThread.h" |
| +#include "wtf/Functional.h" |
| +#include "wtf/Noncopyable.h" |
| +#include "wtf/ThreadingPrimitives.h" |
| +#include <deque> |
|
eseidel
2014/07/15 19:32:37
Why is this needed?
Sami
2014/07/16 10:28:07
Oops, left over from an earlier version. I've clea
|
| + |
| +namespace WebCore { |
| + |
| +// The scheduler is an opinionated gateway for arranging work to be run the |
| +// main thread. It decides which tasks get priority over others based on a |
| +// scheduling policy and the overall system state. |
| +class PLATFORM_EXPORT Scheduler { |
| + WTF_MAKE_NONCOPYABLE(Scheduler); |
| +public: |
| + typedef Function<void()> Task; |
| + |
| + static Scheduler* shared(); |
| + static void initializeOnMainThread(); |
| + static void shutdown(); |
| + |
| + // The following entrypoints are used to schedule different types of tasks |
| + // to be run on the main thread. They can be called from any thread. |
| + void postInputTask(const Task&); |
| + void postCompositorTask(const Task&); |
| + void postTask(const Task&); // For generic (low priority) tasks. |
| + |
| + // Returns true if there is high priority work pending on the main thread |
| + // and the caller should yield to let the scheduler service that work. |
| + // Can be called on the main thread. |
| + bool shouldYieldForHighPriorityWork(); |
| + |
| + // The shared timer can be used to schedule a periodic callback which may |
| + // get preempted by higher priority work. |
| + void setSharedTimerFiredFunction(void (*function)()); |
| + void setSharedTimerFireInterval(double); |
| + void stopSharedTimer(); |
| + |
| +private: |
| + Scheduler(); |
| + ~Scheduler(); |
| + |
| + void scheduleTask(const Task&); |
| + |
| + static void sharedTimerAdapter(); |
| + void tickSharedTimer(); |
| + |
| + static Scheduler* s_sharedScheduler; |
| + blink::WebThread* m_mainThread; |
| + |
| + void (*m_sharedTimerFunction)(); |
| +}; |
| + |
| +} // namespace WebCore |
| + |
| +#endif // Scheduler_h |