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

Side by Side Diff: Source/wtf/DoubleBufferedDeque.h

Issue 540373002: Add support for Low Priorirty tasks. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Maybe fix linker issue Created 6 years, 3 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
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 DoubleBufferedDeque() 17 DoubleBufferedDeque()
18 : m_activeIndex(0) { } 18 : m_activeIndex(0) { }
19 19
20 void append(const T& value) 20 void append(const T& value)
21 { 21 {
22 m_queue[m_activeIndex].append(value); 22 m_queue[m_activeIndex].append(value);
23 } 23 }
24 24
25 bool isEmpty() const 25 bool isEmpty() const
26 { 26 {
27 return m_queue[m_activeIndex].isEmpty(); 27 return m_queue[m_activeIndex].isEmpty();
28 } 28 }
29 29
30 size_t allQueuesSize() const
31 {
32 return m_queue[0].size() + m_queue[1].size();
33 }
34
30 Deque<T>& swapBuffers() 35 Deque<T>& swapBuffers()
31 { 36 {
32 int oldIndex = m_activeIndex; 37 int oldIndex = m_activeIndex;
33 m_activeIndex ^= 1; 38 m_activeIndex ^= 1;
34 ASSERT(m_queue[m_activeIndex].isEmpty()); 39 ASSERT(m_queue[m_activeIndex].isEmpty());
35 return m_queue[oldIndex]; 40 return m_queue[oldIndex];
36 } 41 }
37 42
38 private: 43 private:
39 Deque<T> m_queue[2]; 44 Deque<T> m_queue[2];
40 int m_activeIndex; 45 int m_activeIndex;
41 }; 46 };
42 47
43 } // namespace WTF 48 } // namespace WTF
44 49
45 using WTF::DoubleBufferedDeque; 50 using WTF::DoubleBufferedDeque;
46 51
47 #endif // DoubleBufferedDeque_h 52 #endif // DoubleBufferedDeque_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698