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

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

Issue 439923006: Prioritizing input and compositor tasks in the blink scheduler. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Responding to Sami's feedback Created 6 years, 4 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') | Source/platform/scheduler/Scheduler.cpp » ('J')
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 c492e580aa17268afe30b6c439a9c08acd08638f..2467766d4857b3f0e13684574993d0670f2a8e3a 100644
--- a/Source/platform/scheduler/Scheduler.h
+++ b/Source/platform/scheduler/Scheduler.h
@@ -6,8 +6,11 @@
#define Scheduler_h
#include "platform/PlatformExport.h"
+#include "platform/TraceLocation.h"
+#include "wtf/DoubleBufferedDeque.h"
#include "wtf/Functional.h"
#include "wtf/Noncopyable.h"
+#include "wtf/ThreadingPrimitives.h"
namespace blink {
class WebThread;
@@ -15,8 +18,6 @@ class WebThread;
namespace blink {
-class TraceLocation;
-
// The scheduler is an opinionated gateway for arranging work to be run on the
// main thread. It decides which tasks get priority over others based on a
// scheduling policy and the overall system state.
@@ -36,12 +37,12 @@ public:
void postInputTask(const TraceLocation&, const Task&);
void postCompositorTask(const TraceLocation&, const Task&);
void postTask(const TraceLocation&, const Task&); // For generic (low priority) tasks.
- void postIdleTask(const IdleTask&); // For non-critical tasks which may be reordered relative to other task types.
+ void postIdleTask(const TraceLocation&, const IdleTask&); // For non-critical tasks which may be reordered relative to other task types.
// Returns true if there is high priority work pending on the main thread
// and the caller should yield to let the scheduler service that work.
- // Can be called on the main thread.
- bool shouldYieldForHighPriorityWork();
+ // Can be called on any thread.
+ bool shouldYieldForHighPriorityWork() const;
// The shared timer can be used to schedule a periodic callback which may
// get preempted by higher priority work.
@@ -50,19 +51,49 @@ public:
void stopSharedTimer();
private:
+ class MainThreadPendingTaskRunner;
+ class MainThreadPendingHighPriorityTaskRunner;
+ friend class MainThreadPendingTaskRunner;
+ friend class MainThreadPendingHighPriorityTaskRunner;
+
Scheduler();
~Scheduler();
- void scheduleTask(const TraceLocation&, const Task&);
- void scheduleIdleTask(const IdleTask&);
+ void scheduleIdleTask(const TraceLocation&, const IdleTask&);
static void sharedTimerAdapter();
void tickSharedTimer();
+ bool hasPendingHighPriorityWork() const;
+ void runHighPriorityTasks();
+
static Scheduler* s_sharedScheduler;
- blink::WebThread* m_mainThread;
+ class TracedTask {
+ public:
+ TracedTask(const Task& task, const TraceLocation& location)
+ : m_task(task)
+ , m_location(location) { }
+
+ void run();
+
+ private:
+ Task m_task;
+ TraceLocation m_location;
+ };
+
+ // Should only be accessed from the main thread.
void (*m_sharedTimerFunction)();
+
+ // These members can be accessed from any thread.
+ WebThread* m_mainThread;
+
+ // This mutex protects calls to the pending task queues.
+ Mutex m_pendingTasksMutex;
+ DoubleBufferedDeque<TracedTask> m_pendingInputTasks;
+ DoubleBufferedDeque<TracedTask> m_pendingCompositorTasks;
+
+ volatile int m_highPriorityTaskCount;
};
} // namespace blink
« no previous file with comments | « no previous file | Source/platform/scheduler/Scheduler.cpp » ('j') | Source/platform/scheduler/Scheduler.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698