Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright (C) 2014 Google Inc. All rights reserved. | |
|
eseidel
2014/07/15 15:59:11
Please use the updated 2-line license. instead of
Sami
2014/07/15 19:20:05
Ah, somehow I thought that was only for Chromium c
| |
| 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 * 1. Redistributions of source code must retain the above copyright | |
| 8 * notice, this list of conditions and the following disclaimer. | |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | |
| 10 * notice, this list of conditions and the following disclaimer in the | |
| 11 * documentation and/or other materials provided with the distribution. | |
| 12 * | |
| 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' | |
| 14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | |
| 15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
| 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS | |
| 17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
| 18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
| 19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
| 20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
| 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
| 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | |
| 23 * THE POSSIBILITY OF SUCH DAMAGE. | |
| 24 */ | |
| 25 | |
| 26 #ifndef Scheduler_h | |
| 27 #define Scheduler_h | |
| 28 | |
| 29 #include "platform/PlatformExport.h" | |
| 30 #include "public/platform/WebThread.h" | |
| 31 #include "wtf/Functional.h" | |
| 32 #include "wtf/Noncopyable.h" | |
| 33 #include "wtf/ThreadingPrimitives.h" | |
| 34 #include <deque> | |
| 35 | |
| 36 namespace WebCore { | |
| 37 | |
| 38 // The scheduler is an opinionated gateway for arranging work to be run the | |
| 39 // main thread. It decides which tasks get priority over others based on a | |
| 40 // scheduling policy and the overall system state. | |
| 41 class PLATFORM_EXPORT Scheduler { | |
| 42 WTF_MAKE_NONCOPYABLE(Scheduler); | |
| 43 public: | |
| 44 typedef Function<void()> Task; | |
| 45 | |
| 46 static Scheduler* current(); | |
| 47 static void initializeOnMainThread(); | |
| 48 static void shutdown(); | |
| 49 | |
| 50 // The following entrypoints are used to schedule different types of tasks | |
| 51 // to be run on the main thread. They can be called from any thread. | |
| 52 void postInputTask(const Task&); | |
| 53 void postCompositorTask(const Task&); | |
| 54 void postTask(const Task&); // For generic (low priority) tasks. | |
| 55 | |
| 56 // Returns true if there is high priority work pending on the main thread | |
| 57 // and the caller should yield to let the scheduler service that work. | |
| 58 // Can be called on the main thread. | |
| 59 bool shouldYieldForHighPriorityWork(); | |
| 60 | |
| 61 // The shared timer can be used to schedule a periodic callback which may | |
| 62 // get preempted by higher priority work. | |
| 63 void setSharedTimerFiredFunction(void (*function)()); | |
| 64 void setSharedTimerFireInterval(double); | |
| 65 void stopSharedTimer(); | |
| 66 | |
| 67 private: | |
| 68 Scheduler(); | |
| 69 ~Scheduler(); | |
| 70 | |
| 71 void scheduleTask(const Task&); | |
| 72 | |
| 73 static void sharedTimerAdapter(); | |
| 74 void tickSharedTimer(); | |
| 75 | |
| 76 static Scheduler* s_currentScheduler; | |
| 77 blink::WebThread* m_mainThread; | |
| 78 | |
| 79 void (*m_sharedTimerFunction)(); | |
| 80 }; | |
| 81 | |
| 82 } // namespace WebCore | |
| 83 | |
| 84 #endif // Scheduler_h | |
| OLD | NEW |