OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef DoubleBufferedDeque_h | |
6 #define DoubleBufferedDeque_h | |
7 | |
8 #include "wtf/Deque.h" | |
9 #include "wtf/Noncopyable.h" | |
10 | |
11 namespace WTF { | |
12 | |
13 template <typename T> class DoubleBufferedDeque { | |
eseidel
2014/08/12 16:16:01
I might add a small comment as to what this classs
alexclarke
2014/08/13 10:08:59
Done.
| |
14 WTF_MAKE_NONCOPYABLE(DoubleBufferedDeque); | |
15 public: | |
16 DoubleBufferedDeque() | |
17 : m_activeIndex(0) { } | |
18 | |
19 void append(const T& value) | |
20 { | |
21 m_queue[m_activeIndex].append(value); | |
22 } | |
23 | |
24 bool isEmpty() const | |
25 { | |
26 return m_queue[m_activeIndex].isEmpty(); | |
27 } | |
28 | |
29 Deque<T>& swapBuffers() | |
30 { | |
31 int oldIndex = m_activeIndex; | |
32 m_activeIndex ^= 1; | |
33 ASSERT(m_queue[m_activeIndex].isEmpty()); | |
34 return m_queue[oldIndex]; | |
35 } | |
36 | |
37 private: | |
38 Deque<T> m_queue[2]; | |
39 int m_activeIndex; | |
40 }; | |
41 | |
42 } // namespace WTF | |
43 | |
44 using WTF::DoubleBufferedDeque; | |
45 | |
46 #endif // DoubleBufferedDeque_h | |
OLD | NEW |