-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotification_queue.cpp
More file actions
53 lines (50 loc) · 954 Bytes
/
notification_queue.cpp
File metadata and controls
53 lines (50 loc) · 954 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
41
42
43
44
45
46
47
48
49
50
51
52
53
/**
* @file notification_queue.cpp
* @author d.deka (https://ddeka0.github.io/)
* @brief
* @version 0.1
* @date 2021-02-14
*
*/
#include "notification_queue.hpp"
#include "logger.hpp"
/** done()
* @brief
* Thread safe queue, where user threads are kept
*/
void notification_queue::done() {
{
lock_t lock{_mutex};
_done = true;
}
_ready.notify_all();
}
/**
* @brief pop(ThreadCtx** x)
*
* @param x
* @return true
* @return false
*/
bool notification_queue::pop(ThreadCtx** x) {
lock_t lock{_mutex};
_ready.wait(lock,[this]() {
Log("Sleeping ....TID = ",THIS_THREAD_ID);
return !_q.empty() || _done;
});
if(_q.empty() || _done) {
return false;
}
*x = std::move(_q.front());
_q.pop_front();
return true;
}
/**
* @brief
*
* @return std::size_t
*/
std::size_t notification_queue::get_size() {
lock_t lock{_mutex};
return _q.size();
}