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 "platform/TraceLocation.h" | |
| 10 #include "public/platform/WebThread.h" | |
| 11 #include "wtf/Deque.h" | |
| 9 #include "wtf/Functional.h" | 12 #include "wtf/Functional.h" |
| 10 #include "wtf/Noncopyable.h" | 13 #include "wtf/Noncopyable.h" |
| 14 #include "wtf/ThreadingPrimitives.h" | |
| 11 | 15 |
| 12 namespace blink { | 16 namespace blink { |
| 13 class WebThread; | 17 class WebThread; |
| 14 } | 18 } |
| 15 | 19 |
| 16 namespace blink { | 20 namespace blink { |
| 17 | 21 |
| 18 class TraceLocation; | 22 class TraceLocation; |
|
Sami
2014/08/07 15:51:27
I think this forward declaration can be removed no
| |
| 19 | 23 |
| 20 // The scheduler is an opinionated gateway for arranging work to be run on the | 24 // The scheduler is an opinionated gateway for arranging work to be run on the |
| 21 // main thread. It decides which tasks get priority over others based on a | 25 // main thread. It decides which tasks get priority over others based on a |
| 22 // scheduling policy and the overall system state. | 26 // scheduling policy and the overall system state. |
| 23 class PLATFORM_EXPORT Scheduler { | 27 class PLATFORM_EXPORT Scheduler { |
| 24 WTF_MAKE_NONCOPYABLE(Scheduler); | 28 WTF_MAKE_NONCOPYABLE(Scheduler); |
| 25 public: | 29 public: |
| 26 typedef Function<void()> Task; | 30 typedef Function<void()> Task; |
| 27 // An IdleTask is passed an allotted time in CLOCK_MONOTONIC milliseconds an d is expected to complete within this timeframe. | 31 // An IdleTask is passed an allotted time in CLOCK_MONOTONIC milliseconds an d is expected to complete within this timeframe. |
| 28 typedef Function<void(double allottedTimeMs)> IdleTask; | 32 typedef Function<void(double allottedTimeMs)> IdleTask; |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 46 // The shared timer can be used to schedule a periodic callback which may | 50 // The shared timer can be used to schedule a periodic callback which may |
| 47 // get preempted by higher priority work. | 51 // get preempted by higher priority work. |
| 48 void setSharedTimerFiredFunction(void (*function)()); | 52 void setSharedTimerFiredFunction(void (*function)()); |
| 49 void setSharedTimerFireInterval(double); | 53 void setSharedTimerFireInterval(double); |
| 50 void stopSharedTimer(); | 54 void stopSharedTimer(); |
| 51 | 55 |
| 52 private: | 56 private: |
| 53 Scheduler(); | 57 Scheduler(); |
| 54 ~Scheduler(); | 58 ~Scheduler(); |
| 55 | 59 |
| 56 void scheduleTask(const TraceLocation&, const Task&); | |
| 57 void scheduleIdleTask(const IdleTask&); | 60 void scheduleIdleTask(const IdleTask&); |
| 58 | 61 |
| 59 static void sharedTimerAdapter(); | 62 static void sharedTimerAdapter(); |
| 60 void tickSharedTimer(); | 63 void tickSharedTimer(); |
| 61 | 64 |
| 62 static Scheduler* s_sharedScheduler; | 65 static Scheduler* s_sharedScheduler; |
| 66 | |
| 67 class TracedTask { | |
| 68 public: | |
| 69 TracedTask(const Task& task, const TraceLocation& location) | |
| 70 : m_task(task) | |
| 71 , m_location(location) { } | |
| 72 | |
| 73 void run(); | |
| 74 | |
| 75 private: | |
| 76 Task m_task; | |
| 77 TraceLocation m_location; | |
| 78 }; | |
| 79 | |
| 80 class LockingTracedTaskDeque { | |
| 81 public: | |
| 82 void append(const TracedTask& value); | |
| 83 bool isEmpty(); | |
| 84 | |
| 85 // Returns true if a task was executed, false otherwise. | |
| 86 bool runFirstTaskIfNotEmpty(); | |
| 87 | |
| 88 private: | |
| 89 WTF::Deque<TracedTask> m_queue; | |
| 90 Mutex m_mutex; | |
| 91 }; | |
| 92 | |
| 93 class MainThreadPendingTaskRunner; | |
|
Sami
2014/08/07 15:51:26
It doesn't look like this declaration is needed?
| |
| 94 | |
| 95 // These members can be accessed from any thread. | |
| 63 blink::WebThread* m_mainThread; | 96 blink::WebThread* m_mainThread; |
| 97 LockingTracedTaskDeque m_pendingInputTasks; | |
| 98 LockingTracedTaskDeque m_pendingCompositorTasks; | |
| 99 LockingTracedTaskDeque m_pendingLowPriorityTasks; | |
| 100 void (*m_sharedTimerFunction)(); | |
|
Sami
2014/08/07 15:51:26
This should be separated from the cross-thread fie
| |
| 101 volatile int m_mainThreadInFlight; | |
| 64 | 102 |
| 65 void (*m_sharedTimerFunction)(); | 103 void maybePostTaskLoopOnMainThread(); |
|
Sami
2014/08/07 15:51:26
Looks like these got moved after the data members
| |
| 104 void runHighPriorityTasks(); | |
| 105 void runPendingTasks(); | |
| 106 | |
| 107 friend class MainThreadPendingTaskRunner; | |
|
Sami
2014/08/07 15:51:27
Could you move this right after the private: line?
| |
| 66 }; | 108 }; |
| 67 | 109 |
| 68 } // namespace blink | 110 } // namespace blink |
| 69 | 111 |
| 70 #endif // Scheduler_h | 112 #endif // Scheduler_h |
| OLD | NEW |