| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef Scheduler_h | 5 #ifndef Scheduler_h |
| 6 #define Scheduler_h | 6 #define Scheduler_h |
| 7 | 7 |
| 8 #include "platform/PlatformExport.h" | 8 #include "platform/PlatformExport.h" |
| 9 #include "wtf/Functional.h" | 9 #include "wtf/Functional.h" |
| 10 #include "wtf/Noncopyable.h" | 10 #include "wtf/Noncopyable.h" |
| 11 #include "wtf/PassOwnPtr.h" |
| 11 | 12 |
| 12 namespace blink { | 13 namespace blink { |
| 13 class TraceLocation; | 14 class TraceLocation; |
| 14 class WebScheduler; | 15 class WebScheduler; |
| 15 | 16 |
| 16 // The scheduler is an opinionated gateway for arranging work to be run on the | 17 // The scheduler is an opinionated gateway for arranging work to be run on the |
| 17 // main thread. It decides which tasks get priority over others based on a | 18 // main thread. It decides which tasks get priority over others based on a |
| 18 // scheduling policy and the overall system state. | 19 // scheduling policy and the overall system state. |
| 19 class PLATFORM_EXPORT Scheduler { | 20 class PLATFORM_EXPORT Scheduler { |
| 20 WTF_MAKE_NONCOPYABLE(Scheduler); | 21 WTF_MAKE_NONCOPYABLE(Scheduler); |
| 21 public: | 22 public: |
| 22 // An IdleTask is passed a deadline in CLOCK_MONOTONIC seconds and is expect
ed to complete before this deadline. | 23 // An IdleTask is passed a deadline in CLOCK_MONOTONIC seconds and is expect
ed to complete before this deadline. |
| 23 typedef Function<void(double deadlineSeconds)> IdleTask; | 24 typedef Function<void(double deadlineSeconds)> IdleTask; |
| 24 | 25 |
| 25 static Scheduler* shared(); | 26 static Scheduler* shared(); |
| 26 static void shutdown(); | 27 static void shutdown(); |
| 27 | 28 |
| 28 // For non-critical tasks which may be reordered relative to other task type
s and may be starved | 29 // For non-critical tasks which may be reordered relative to other task type
s and may be starved |
| 29 // for an arbitrarily long time if no idle time is available. | 30 // for an arbitrarily long time if no idle time is available. |
| 30 void postIdleTask(const TraceLocation&, const IdleTask&); | 31 void postIdleTask(const TraceLocation&, PassOwnPtr<IdleTask>); |
| 31 | 32 |
| 32 // Returns true if there is high priority work pending on the main thread | 33 // Returns true if there is high priority work pending on the main thread |
| 33 // and the caller should yield to let the scheduler service that work. | 34 // and the caller should yield to let the scheduler service that work. |
| 34 // Must be called on the main thread. | 35 // Must be called on the main thread. |
| 35 bool shouldYieldForHighPriorityWork() const; | 36 bool shouldYieldForHighPriorityWork() const; |
| 36 | 37 |
| 37 protected: | 38 protected: |
| 38 Scheduler(WebScheduler*); | 39 Scheduler(WebScheduler*); |
| 39 virtual ~Scheduler(); | 40 virtual ~Scheduler(); |
| 40 | 41 |
| 41 static Scheduler* s_sharedScheduler; | 42 static Scheduler* s_sharedScheduler; |
| 42 WebScheduler* m_webScheduler; | 43 WebScheduler* m_webScheduler; |
| 43 }; | 44 }; |
| 44 | 45 |
| 45 } // namespace blink | 46 } // namespace blink |
| 46 | 47 |
| 47 #endif // Scheduler_h | 48 #endif // Scheduler_h |
| OLD | NEW |