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

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

Issue 364873002: Introduce a basic Blink Scheduler (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Build fix for old gcc. Created 6 years, 5 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
Index: Source/platform/scheduler/Scheduler.h
diff --git a/Source/platform/scheduler/Scheduler.h b/Source/platform/scheduler/Scheduler.h
new file mode 100644
index 0000000000000000000000000000000000000000..56b59e02cb074a0990e4cf3027d27e106c8358de
--- /dev/null
+++ b/Source/platform/scheduler/Scheduler.h
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) 2014 Google Inc. All rights reserved.
eseidel 2014/07/15 15:59:11 Please use the updated 2-line license. instead of
Sami 2014/07/15 19:20:05 Ah, somehow I thought that was only for Chromium c
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef Scheduler_h
+#define Scheduler_h
+
+#include "platform/PlatformExport.h"
+#include "public/platform/WebThread.h"
+#include "wtf/Functional.h"
+#include "wtf/Noncopyable.h"
+#include "wtf/ThreadingPrimitives.h"
+#include <deque>
+
+namespace WebCore {
+
+// The scheduler is an opinionated gateway for arranging work to be run the
+// main thread. It decides which tasks get priority over others based on a
+// scheduling policy and the overall system state.
+class PLATFORM_EXPORT Scheduler {
+ WTF_MAKE_NONCOPYABLE(Scheduler);
+public:
+ typedef Function<void()> Task;
+
+ static Scheduler* current();
+ static void initializeOnMainThread();
+ static void shutdown();
+
+ // The following entrypoints are used to schedule different types of tasks
+ // to be run on the main thread. They can be called from any thread.
+ void postInputTask(const Task&);
+ void postCompositorTask(const Task&);
+ void postTask(const Task&); // For generic (low priority) tasks.
+
+ // 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();
+
+ // The shared timer can be used to schedule a periodic callback which may
+ // get preempted by higher priority work.
+ void setSharedTimerFiredFunction(void (*function)());
+ void setSharedTimerFireInterval(double);
+ void stopSharedTimer();
+
+private:
+ Scheduler();
+ ~Scheduler();
+
+ void scheduleTask(const Task&);
+
+ static void sharedTimerAdapter();
+ void tickSharedTimer();
+
+ static Scheduler* s_currentScheduler;
+ blink::WebThread* m_mainThread;
+
+ void (*m_sharedTimerFunction)();
+};
+
+} // namespace WebCore
+
+#endif // Scheduler_h

Powered by Google App Engine
This is Rietveld 408576698