blob: 65e6bfa3b0c59dbeb841b1b4b4a5329c49601cbb (
plain)
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
58
|
#include "drape_frontend/message_queue.hpp"
#include "base/assert.hpp"
#include "base/stl_add.hpp"
namespace df
{
MessageQueue::~MessageQueue()
{
CancelWait();
ClearQuery();
}
dp::TransferPointer<Message> MessageQueue::PopMessage(unsigned maxTimeWait)
{
threads::ConditionGuard guard(m_condition);
WaitMessage(maxTimeWait);
/// even waitNonEmpty == true m_messages can be empty after WaitMessage call
/// if application preparing to close and CancelWait been called
if (m_messages.empty())
return dp::MovePointer<Message>(NULL);
dp::MasterPointer<Message> msg = m_messages.front();
m_messages.pop_front();
return msg.Move();
}
void MessageQueue::PushMessage(dp::TransferPointer<Message> message)
{
threads::ConditionGuard guard(m_condition);
bool wasEmpty = m_messages.empty();
m_messages.push_back(dp::MasterPointer<Message>(message));
if (wasEmpty)
guard.Signal();
}
void MessageQueue::WaitMessage(unsigned maxTimeWait)
{
if (m_messages.empty())
m_condition.Wait(maxTimeWait);
}
void MessageQueue::CancelWait()
{
m_condition.Signal();
}
void MessageQueue::ClearQuery()
{
DeleteRange(m_messages, dp::MasterPointerDeleter());
}
} // namespace df
|