blob: 6caaa1f29255a2766acdfc75bba7c102c67f46ec (
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
|
#pragma once
#include "drape_frontend/message.hpp"
#include "drape/pointers.hpp"
#include "base/condition.hpp"
#include "std/condition_variable.hpp"
#include "std/deque.hpp"
#include "std/mutex.hpp"
namespace df
{
//#define DEBUG_MESSAGE_QUEUE
class MessageQueue
{
public:
MessageQueue();
~MessageQueue();
/// if queue is empty then return NULL
drape_ptr<Message> PopMessage(bool waitForMessage);
void PushMessage(drape_ptr<Message> && message, MessagePriority priority);
void CancelWait();
void ClearQuery();
using TFilterMessageFn = function<bool (ref_ptr<Message>)>;
void FilterMessages(TFilterMessageFn needFilterMessageFn);
#ifdef DEBUG_MESSAGE_QUEUE
bool IsEmpty() const;
size_t GetSize() const;
#endif
private:
void CancelWaitImpl();
mutable mutex m_mutex;
condition_variable m_condition;
bool m_isWaiting;
using TMessageNode = pair<drape_ptr<Message>, MessagePriority>;
deque<TMessageNode> m_messages;
};
} // namespace df
|