mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
I wrote a script to do this which is attached to the bug. TBR=abarth@chromium.org BUG=435361 Review URL: https://codereview.chromium.org/736373003
48 lines
1.1 KiB
C++
48 lines
1.1 KiB
C++
// Copyright 2014 The Chromium Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#ifndef SKY_ENGINE_WTF_DOUBLEBUFFEREDDEQUE_H_
|
|
#define SKY_ENGINE_WTF_DOUBLEBUFFEREDDEQUE_H_
|
|
|
|
#include "sky/engine/wtf/Deque.h"
|
|
#include "sky/engine/wtf/Noncopyable.h"
|
|
|
|
namespace WTF {
|
|
|
|
// A helper class for managing double buffered deques, typically where the client locks when appending or swapping.
|
|
template <typename T> class DoubleBufferedDeque {
|
|
WTF_MAKE_NONCOPYABLE(DoubleBufferedDeque);
|
|
public:
|
|
DoubleBufferedDeque()
|
|
: m_activeIndex(0) { }
|
|
|
|
void append(const T& value)
|
|
{
|
|
m_queue[m_activeIndex].append(value);
|
|
}
|
|
|
|
bool isEmpty() const
|
|
{
|
|
return m_queue[m_activeIndex].isEmpty();
|
|
}
|
|
|
|
Deque<T>& swapBuffers()
|
|
{
|
|
int oldIndex = m_activeIndex;
|
|
m_activeIndex ^= 1;
|
|
ASSERT(m_queue[m_activeIndex].isEmpty());
|
|
return m_queue[oldIndex];
|
|
}
|
|
|
|
private:
|
|
Deque<T> m_queue[2];
|
|
int m_activeIndex;
|
|
};
|
|
|
|
} // namespace WTF
|
|
|
|
using WTF::DoubleBufferedDeque;
|
|
|
|
#endif // SKY_ENGINE_WTF_DOUBLEBUFFEREDDEQUE_H_
|