This source file includes following definitions.
- m_readPosition
- setData
- data
- hasNewData
#include "config.h"
#include "platform/graphics/ThreadSafeDataTransport.h"
#include "platform/SharedBuffer.h"
namespace WebCore {
ThreadSafeDataTransport::ThreadSafeDataTransport()
: m_readBuffer(SharedBuffer::create())
, m_allDataReceived(false)
, m_readPosition(0)
{
}
ThreadSafeDataTransport::~ThreadSafeDataTransport()
{
}
void ThreadSafeDataTransport::setData(SharedBuffer* buffer, bool allDataReceived)
{
ASSERT(buffer->size() >= m_readPosition);
Vector<RefPtr<SharedBuffer> > newBufferQueue;
const char* segment = 0;
while (size_t length = buffer->getSomeData(segment, m_readPosition)) {
m_readPosition += length;
newBufferQueue.append(SharedBuffer::create(segment, length));
}
MutexLocker locker(m_mutex);
m_newBufferQueue.appendVector(newBufferQueue);
m_allDataReceived = allDataReceived;
}
void ThreadSafeDataTransport::data(SharedBuffer** buffer, bool* allDataReceived)
{
Vector<RefPtr<SharedBuffer> > newBufferQueue;
{
MutexLocker lock(m_mutex);
m_newBufferQueue.swap(newBufferQueue);
}
for (size_t i = 0; i < newBufferQueue.size(); ++i)
m_readBuffer->append(newBufferQueue[i].get());
ASSERT(buffer);
ASSERT(allDataReceived);
*buffer = m_readBuffer.get();
*allDataReceived = m_allDataReceived;
}
bool ThreadSafeDataTransport::hasNewData()
{
MutexLocker lock(m_mutex);
return !m_newBufferQueue.isEmpty();
}
}