Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef DoubleBufferedDeque_h | 5 #ifndef DoubleBufferedDeque_h |
| 6 #define DoubleBufferedDeque_h | 6 #define DoubleBufferedDeque_h |
| 7 | 7 |
| 8 #include "wtf/Deque.h" | 8 #include "wtf/Deque.h" |
| 9 #include "wtf/Noncopyable.h" | 9 #include "wtf/Noncopyable.h" |
| 10 | 10 |
| 11 namespace WTF { | 11 namespace WTF { |
| 12 | 12 |
| 13 // A helper class for managing double buffered deques, typically where the clien t locks when appending or swapping. | 13 // A helper class for managing double buffered deques, typically where the clien t locks when appending or swapping. |
| 14 template <typename T> class DoubleBufferedDeque { | 14 template <typename T> class DoubleBufferedDeque { |
| 15 WTF_MAKE_NONCOPYABLE(DoubleBufferedDeque); | 15 WTF_MAKE_NONCOPYABLE(DoubleBufferedDeque); |
| 16 public: | 16 public: |
| 17 typedef typename PassTraits<T>::PassType PassType; | |
| 17 DoubleBufferedDeque() | 18 DoubleBufferedDeque() |
| 18 : m_activeIndex(0) { } | 19 : m_activeIndex(0) { } |
| 19 | 20 |
| 20 void append(const T& value) | 21 void append(const PassType& value) |
|
Sami
2014/09/24 14:00:40
Is this an optimization to avoid copies or somethi
rmcilroy
2014/09/29 17:42:58
This is required to be able to create a DoubleBuff
| |
| 21 { | 22 { |
| 22 m_queue[m_activeIndex].append(value); | 23 m_queue[m_activeIndex].append(value); |
| 23 } | 24 } |
| 24 | 25 |
|
picksi1
2014/09/25 08:53:31
FWIW during my refactor I stopped using the Double
rmcilroy
2014/09/29 17:42:58
I would much prefer to fix this DoubleBufferedDequ
picksi1
2014/09/30 09:13:51
My changes felt against the spirit of the DoubleBu
rmcilroy
2014/09/30 09:56:19
Makes sense. You should never be scared of causing
| |
| 25 bool isEmpty() const | 26 bool isEmpty() const |
| 26 { | 27 { |
| 27 return m_queue[m_activeIndex].isEmpty(); | 28 return m_queue[m_activeIndex].isEmpty(); |
| 28 } | 29 } |
| 29 | 30 |
| 30 Deque<T>& swapBuffers() | 31 Deque<T>& swapBuffers() |
| 31 { | 32 { |
| 32 int oldIndex = m_activeIndex; | 33 int oldIndex = m_activeIndex; |
| 33 m_activeIndex ^= 1; | 34 m_activeIndex ^= 1; |
| 34 ASSERT(m_queue[m_activeIndex].isEmpty()); | 35 ASSERT(m_queue[m_activeIndex].isEmpty()); |
| 35 return m_queue[oldIndex]; | 36 return m_queue[oldIndex]; |
| 36 } | 37 } |
| 37 | 38 |
| 38 private: | 39 private: |
| 39 Deque<T> m_queue[2]; | 40 Deque<T> m_queue[2]; |
| 40 int m_activeIndex; | 41 int m_activeIndex; |
| 41 }; | 42 }; |
| 42 | 43 |
| 43 } // namespace WTF | 44 } // namespace WTF |
| 44 | 45 |
| 45 using WTF::DoubleBufferedDeque; | 46 using WTF::DoubleBufferedDeque; |
| 46 | 47 |
| 47 #endif // DoubleBufferedDeque_h | 48 #endif // DoubleBufferedDeque_h |
| OLD | NEW |