-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotification_queue.hpp
More file actions
44 lines (40 loc) · 844 Bytes
/
notification_queue.hpp
File metadata and controls
44 lines (40 loc) · 844 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
/**
* @file notification_queue.hpp
* @author d.deka (https://ddeka0.github.io/)
* @brief
* @version 0.1
* @date 2021-02-14
*
*/
#pragma once
#include <thread>
#include <concepts>
#include "threadCtx.hpp"
#include <stdio.h>
#include <deque>
#include <condition_variable>
/**
* @brief
* Thread safe queue, where user threads are kept
*/
class notification_queue {
private:
std::deque<ThreadCtx*> _q;
bool _done{false};
std::mutex _mutex;
std::condition_variable _ready;
using lock_t = std::unique_lock<std::mutex>;
public:
void done();
bool pop(ThreadCtx** x);
// Test purpose ...
std::size_t get_size();
template<typename F>
void push(F&& f) {
{
lock_t lock{_mutex};
_q.emplace_back(std::forward<F>(f));
}
_ready.notify_one();
}
};