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

Unified Diff: Source/wtf/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: Adding a missing #include 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 | « Source/platform/scheduler/SchedulerTest.cpp ('k') | Source/wtf/DoubleBufferedDequeTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/wtf/DoubleBufferedDeque.h
diff --git a/Source/wtf/DoubleBufferedDeque.h b/Source/wtf/DoubleBufferedDeque.h
new file mode 100644
index 0000000000000000000000000000000000000000..5343f00c7770b37326eabc4f8e00fe1eb0ced0a7
--- /dev/null
+++ b/Source/wtf/DoubleBufferedDeque.h
@@ -0,0 +1,47 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef DoubleBufferedDeque_h
+#define DoubleBufferedDeque_h
+
+#include "wtf/Deque.h"
+#include "wtf/Noncopyable.h"
+
+namespace WTF {
+
+// A helper class for managing double buffered deques, typically where the client locks when appending or swapping.
+template <typename T> class DoubleBufferedDeque {
+ WTF_MAKE_NONCOPYABLE(DoubleBufferedDeque);
+public:
+ DoubleBufferedDeque()
+ : m_activeIndex(0) { }
+
+ void append(const T& value)
+ {
+ m_queue[m_activeIndex].append(value);
+ }
+
+ bool isEmpty() const
+ {
+ return m_queue[m_activeIndex].isEmpty();
+ }
+
+ Deque<T>& swapBuffers()
+ {
+ int oldIndex = m_activeIndex;
+ m_activeIndex ^= 1;
+ ASSERT(m_queue[m_activeIndex].isEmpty());
+ return m_queue[oldIndex];
+ }
+
+private:
+ Deque<T> m_queue[2];
+ int m_activeIndex;
+};
+
+} // namespace WTF
+
+using WTF::DoubleBufferedDeque;
+
+#endif // DoubleBufferedDeque_h
« no previous file with comments | « Source/platform/scheduler/SchedulerTest.cpp ('k') | Source/wtf/DoubleBufferedDequeTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698