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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 #ifndef DoubleBufferedDeque_h
Sami 2014/08/08 15:31:13 Please add a copyright header.
2 #define DoubleBufferedDeque_h
3
4 #include "wtf/Deque.h"
5 #include "wtf/Noncopyable.h"
6 #include "wtf/ThreadingPrimitives.h"
7
8 namespace blink {
9
10 template <typename T> class DoubleBufferedDeque {
11 WTF_MAKE_NONCOPYABLE(DoubleBufferedDeque);
12 public:
13 DoubleBufferedDeque()
14 : m_activeIndex(0) { }
15
16 void append(const T& value)
17 {
18 Locker<Mutex> lock(m_mutex);
19 m_queue[m_activeIndex].append(value);
20 }
21
22 bool isEmpty()
23 {
24 Locker<Mutex> lock(m_mutex);
25 return m_queue[m_activeIndex].isEmpty();
26 }
27
28 WTF::Deque<T>& swapBuffers()
29 {
30 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
31 int oldIndex = m_activeIndex;
32 m_activeIndex ^= 1;
33 return m_queue[oldIndex];
34 }
35
36 private:
37 WTF::Deque<T> m_queue[2];
38 int m_activeIndex;
39 Mutex m_mutex;
40 };
41
42 } // namespace blink
43
44 #endif // DoubleBufferedDeque_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698