-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathMsgQueue.cpp
More file actions
40 lines (33 loc) · 792 Bytes
/
MsgQueue.cpp
File metadata and controls
40 lines (33 loc) · 792 Bytes
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
#include "MsgQueue.h"
namespace Sun {
void MsgQueue::push(const Msg& msg) {
std::unique_lock<std::mutex> lock(mute_);
que_.push(msg);
condition_.notify_one();
}
Msg MsgQueue::front() {
std::unique_lock<std::mutex> lock(mute_);
return que_.front();
}
Msg MsgQueue::pop() {
std::unique_lock<std::mutex> lock(mute_);
Msg msg = que_.front();
que_.pop();
return msg;
}
bool MsgQueue::empty() {
std::unique_lock<std::mutex> lock(mute_);
return que_.empty();
}
void MsgQueue::wait() {
std::unique_lock<std::mutex> lock(mute_);
condition_.wait(lock, [this]() {
return (!que_.empty());
});
}
void MsgQueue::stop_wait() {
std::unique_lock<std::mutex> lock(mute_);
stop_ = true;
condition_.notify_one();
}
}