Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2397)

Unified Diff: Source/platform/scheduler/Scheduler.h

Issue 595023002: Implement idle task scheduling. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fix Expect_EQ Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | Source/platform/scheduler/Scheduler.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/platform/scheduler/Scheduler.h
diff --git a/Source/platform/scheduler/Scheduler.h b/Source/platform/scheduler/Scheduler.h
index ef8366eb75a52c5c898f7c763f678c971fa7d8f3..a2a15f4fc4bcd62bb4e6757cb0b3ed4bf3e3a94d 100644
--- a/Source/platform/scheduler/Scheduler.h
+++ b/Source/platform/scheduler/Scheduler.h
@@ -23,15 +23,15 @@ class PLATFORM_EXPORT Scheduler {
WTF_MAKE_NONCOPYABLE(Scheduler);
public:
typedef Function<void()> Task;
- // An IdleTask is passed an allotted time in CLOCK_MONOTONIC milliseconds and is expected to complete within this timeframe.
- typedef Function<void(double allottedTimeMs)> IdleTask;
+ // An IdleTask is passed a deadline in CLOCK_MONOTONIC seconds and is expected to complete before this deadline.
+ typedef Function<void(double deadlineSeconds)> IdleTask;
static Scheduler* shared();
static void initializeOnMainThread();
static void shutdown();
// Called to notify about the start of a new frame.
- void willBeginFrame(const WebBeginFrameArgs&);
+ void willBeginFrame(double estimatedNextBeginFrameSeconds);
// Called to notify that a previously begun frame was committed.
void didCommitFrameToCompositor();
@@ -42,7 +42,9 @@ public:
void postCompositorTask(const TraceLocation&, const Task&);
void postIpcTask(const TraceLocation&, const Task&);
void postTask(const TraceLocation&, const Task&); // For generic (low priority) tasks.
- void postIdleTask(const TraceLocation&, const IdleTask&); // For non-critical tasks which may be reordered relative to other task types.
+ // For non-critical tasks which may be reordered relative to other task types and may be starved
+ // for an arbitrarily long time if no idle time is available.
+ void postIdleTask(const TraceLocation&, const IdleTask&);
// Tells the scheduler that the system received an input event. This causes the scheduler to go into
// Compositor Priority mode for a short duration.
@@ -59,9 +61,14 @@ public:
void setSharedTimerFireInterval(double);
void stopSharedTimer();
+ // Returns the deadline, in CLOCK_MONOTONIC seconds, which an idle task should
+ // finish by for the current frame.
+ double currentFrameDeadlineForIdleTasks() const;
+
protected:
class MainThreadPendingTaskRunner;
class MainThreadPendingHighPriorityTaskRunner;
+ class MainThreadPendingIdleTaskRunner;
friend class MainThreadPendingTaskRunner;
friend class MainThreadPendingHighPriorityTaskRunner;
@@ -73,8 +80,8 @@ protected:
Scheduler();
virtual ~Scheduler();
- void scheduleIdleTask(const TraceLocation&, const IdleTask&);
void postHighPriorityTaskInternal(const TraceLocation&, const Task&, const char* traceName);
+ void postIdleTaskInternal(const TraceLocation&, const IdleTask&, const char* traceName);
void didRunHighPriorityTask();
static void sharedTimerAdapter();
@@ -84,8 +91,16 @@ protected:
// Only does work in CompositorPriority mode. Returns true if any work was done.
bool runPendingHighPriorityTasksIfInCompositorPriority();
- // Returns true if any work was done.
- bool executeHighPriorityTasks(Deque<TracedTask>&);
+ // Returns true if an idle task was posted to the main thread for execution.
+ bool maybePostMainThreadPendingIdleTask();
+
+ // Only does work if canRunIdleTask. Returns true if any work was done.
+ bool maybeRunPendingIdleTask();
+
+ PassOwnPtr<internal::TracedIdleTask> takeFirstPendingIdleTask();
+
+ // Returns true if the scheduler can run idle tasks at this time.
+ bool canRunIdleTask() const;
// Return the current SchedulerPolicy.
SchedulerPolicy schedulerPolicy() const;
@@ -105,6 +120,12 @@ protected:
WebThread* m_mainThread;
+ // This mutex protects calls to the pending idle task queue.
+ Mutex m_pendingIdleTasksMutex;
+ Deque<OwnPtr<internal::TracedIdleTask>> m_pendingIdleTasks;
+
+ bool m_currentFrameCommitted;
+ double m_estimatedNextBeginFrameSeconds;
// Declared volatile as it is atomically incremented.
volatile int m_highPriorityTaskCount;
« no previous file with comments | « no previous file | Source/platform/scheduler/Scheduler.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698