Chromium Code Reviews| 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 #include "wtf/PassOwnPtr.h" |
| 12 | 12 |
| 13 namespace blink { | 13 namespace blink { |
| 14 class CancellableTask; | |
|
Sami
2015/01/26 16:08:15
Unused?
alex clarke (OOO till 29th)
2015/01/26 17:00:45
Done.
| |
| 14 class TraceLocation; | 15 class TraceLocation; |
| 15 class WebScheduler; | 16 class WebScheduler; |
| 16 | 17 |
| 17 // The scheduler is an opinionated gateway for arranging work to be run on the | 18 // The scheduler is an opinionated gateway for arranging work to be run on the |
| 18 // main thread. It decides which tasks get priority over others based on a | 19 // main thread. It decides which tasks get priority over others based on a |
| 19 // scheduling policy and the overall system state. | 20 // scheduling policy and the overall system state. |
| 20 class PLATFORM_EXPORT Scheduler { | 21 class PLATFORM_EXPORT Scheduler { |
| 21 WTF_MAKE_NONCOPYABLE(Scheduler); | 22 WTF_MAKE_NONCOPYABLE(Scheduler); |
| 22 public: | 23 public: |
| 23 // An IdleTask is passed a deadline in CLOCK_MONOTONIC seconds and is expect ed to complete before this deadline. | 24 // An IdleTask is passed a deadline in CLOCK_MONOTONIC seconds and is expect ed to complete before this deadline. |
| 24 typedef Function<void(double deadlineSeconds)> IdleTask; | 25 typedef Function<void(double deadlineSeconds)> IdleTask; |
| 25 | 26 |
| 26 static Scheduler* shared(); | 27 static Scheduler* shared(); |
| 27 static void shutdown(); | 28 static void shutdown(); |
| 28 | 29 |
| 29 // For non-critical tasks which may be reordered relative to other task type s and may be starved | 30 // For non-critical tasks which may be reordered relative to other task type s and may be starved |
| 30 // for an arbitrarily long time if no idle time is available. | 31 // for an arbitrarily long time if no idle time is available. |
| 31 void postIdleTask(const TraceLocation&, PassOwnPtr<IdleTask>); | 32 void postIdleTask(const TraceLocation&, PassOwnPtr<IdleTask>); |
| 32 | 33 |
| 34 // For tasks related to loading, e.g. HTML parsing. Loading tasks usually h ave default priority | |
| 35 // but they may be deprioritized when the user is interacting with the devic e. | |
| 36 void postLoadingTask(const TraceLocation&, PassOwnPtr<Closure>); | |
|
Sami
2015/01/26 16:08:15
Should we have a variant of this that takes a Task
alex clarke (OOO till 29th)
2015/01/26 17:00:45
I think WebScheduler::postLoadingTask() takes care
rmcilroy
2015/01/26 18:09:01
Would it be worth only having the WebThread::Task
alex clarke (OOO till 29th)
2015/01/27 11:41:19
Done.
| |
| 37 | |
| 33 // Returns true if there is high priority work pending on the main thread | 38 // Returns true if there is high priority work pending on the main thread |
| 34 // and the caller should yield to let the scheduler service that work. | 39 // and the caller should yield to let the scheduler service that work. |
| 35 // Must be called on the main thread. | 40 // Must be called on the main thread. |
| 36 bool shouldYieldForHighPriorityWork() const; | 41 bool shouldYieldForHighPriorityWork() const; |
| 37 | 42 |
| 38 protected: | 43 protected: |
| 39 Scheduler(WebScheduler*); | 44 Scheduler(WebScheduler*); |
| 40 virtual ~Scheduler(); | 45 virtual ~Scheduler(); |
| 41 | 46 |
| 42 static Scheduler* s_sharedScheduler; | 47 static Scheduler* s_sharedScheduler; |
| 43 WebScheduler* m_webScheduler; | 48 WebScheduler* m_webScheduler; |
| 44 }; | 49 }; |
| 45 | 50 |
| 46 } // namespace blink | 51 } // namespace blink |
| 47 | 52 |
| 48 #endif // Scheduler_h | 53 #endif // Scheduler_h |
| OLD | NEW |