OLD | NEW |
---|---|
(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 | |
OLD | NEW |