-
Notifications
You must be signed in to change notification settings - Fork 0
/
ZippedBufferPool.cpp
58 lines (43 loc) · 1.02 KB
/
ZippedBufferPool.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "ZippedBufferPool.hh"
#include "ZippedBuffer.hh"
ZippedBufferPool::ZippedBufferPool(QWaitCondition *waitCondition)
: m_waitCondition(waitCondition),
m_started(false)
{
}
void ZippedBufferPool::put(const ZippedBuffer &zippedBuffer)
{
QMutexLocker locker(&m_mutex);
m_zippedBuffers.push_back(zippedBuffer);
if (m_waitCondition && ! m_started)
{
m_waitCondition->wakeOne();
m_started = true;
}
}
ZippedBuffer ZippedBufferPool::tryGet()
{
QMutexLocker locker(&m_mutex);
ZippedBuffer zippedBuffer;
if ( ! m_zippedBuffers.empty())
{
zippedBuffer = m_zippedBuffers.front();
m_zippedBuffers.pop_front();
}
return zippedBuffer;
}
void ZippedBufferPool::done(bool end)
{
QMutexLocker locker(&m_mutex);
m_done = end;
}
bool ZippedBufferPool::done()
{
QMutexLocker locker(&m_mutex);
return m_done;
}
quint32 ZippedBufferPool::count()
{
QMutexLocker locker(&m_mutex);
return m_zippedBuffers.size();
}