flutter_flutter/engine/wtf/DoubleBufferedDeque.h
Eric Seidel 295f920116 Fix sky include guards to match Chromium style
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
2014-11-21 02:48:38 -08:00

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_