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

Unified Diff: Source/platform/scheduler/DoubleBufferedDeque.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: change to pacify clang 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
Index: Source/platform/scheduler/DoubleBufferedDeque.h
diff --git a/Source/platform/scheduler/DoubleBufferedDeque.h b/Source/platform/scheduler/DoubleBufferedDeque.h
new file mode 100644
index 0000000000000000000000000000000000000000..cfae0599a35d763d91019b86cb409bd4a89012db
--- /dev/null
+++ b/Source/platform/scheduler/DoubleBufferedDeque.h
@@ -0,0 +1,44 @@
+#ifndef DoubleBufferedDeque_h
Sami 2014/08/08 15:31:13 Please add a copyright header.
+#define DoubleBufferedDeque_h
+
+#include "wtf/Deque.h"
+#include "wtf/Noncopyable.h"
+#include "wtf/ThreadingPrimitives.h"
+
+namespace blink {
+
+template <typename T> class DoubleBufferedDeque {
+ WTF_MAKE_NONCOPYABLE(DoubleBufferedDeque);
+public:
+ DoubleBufferedDeque()
+ : m_activeIndex(0) { }
+
+ void append(const T& value)
+ {
+ Locker<Mutex> lock(m_mutex);
+ m_queue[m_activeIndex].append(value);
+ }
+
+ bool isEmpty()
+ {
+ Locker<Mutex> lock(m_mutex);
+ return m_queue[m_activeIndex].isEmpty();
+ }
+
+ WTF::Deque<T>& swapBuffers()
+ {
+ Locker<Mutex> lock(m_mutex);
Sami 2014/08/08 15:31:13 Let's DCHECK that the new queue is empty here. If
alexclarke 2014/08/08 15:47:45 Good idea, although I'll need to change one of the
+ int oldIndex = m_activeIndex;
+ m_activeIndex ^= 1;
+ return m_queue[oldIndex];
+ }
+
+private:
+ WTF::Deque<T> m_queue[2];
+ int m_activeIndex;
+ Mutex m_mutex;
+};
+
+} // namespace blink
+
+#endif // DoubleBufferedDeque_h

Powered by Google App Engine
This is Rietveld 408576698