-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLogQueue.cpp
More file actions
86 lines (69 loc) · 1.84 KB
/
LogQueue.cpp
File metadata and controls
86 lines (69 loc) · 1.84 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include "LogQueue.h"
LogQueue::LogQueue(Shutdown& s,Counter& c) : shutdown(s) , counter(c){ }
LogQueue::~LogQueue() {
{
std::unique_lock<std::mutex> lock(_MUTEX);
shutdown.setShutdownState();
}
_CONDITIONVARIABLE.notify_all();
{
std::unique_lock<std::mutex> lock(_MUTEX);
while (!logsQueue.empty()) { logsQueue.pop(); }
}
}
void LogQueue::pushGeneratedLogs(const text_t& log) {
{
std::unique_lock<std::mutex>lock(_MUTEX);
logsQueue.push(log);
counter.increment();
_logRegContrlVrbl.notify_one();
if (counter.getCounter() >= 20) {
shutdown.setShutdownState();
_CONDITIONVARIABLE.notify_all();
return;
}
}
_CONDITIONVARIABLE.notify_one(); //notifying one thread that we're there's data loaded
}
void LogQueue::popGeneratedLogs() {
{
std::unique_lock<std::mutex>lock(_MUTEX);
_CONDITIONVARIABLE.wait(lock, [&] {return shutdown.getShutdownState() || !logsQueue.empty(); });
if (!logsQueue.empty())
{
printMessage(logsQueue.front(), 50);
logsQueue.pop();
}
}
}
//void LogQueue::showLogRegistration(){
// {
//
// std::unique_lock<std::mutex> lock(_MUTEX);
// _logRegContrlVrbl.wait(lock, [&] {return shutdown.getShutdownState() || counter.getCounter() > 0; });
// size_t value = counter.getCounter();
// if (!logsQueue.empty() && !shutdown.getShutdownState())
// {
// std::cout << value;
// }
// }
//}
//void LogQueue::showLogRegistration()
//{
// value_t lastSeenCounter{ 0 };
// while (!shutdown.getShutdownState())
// {
// std::unique_lock<std::mutex> lock(_MUTEX);
// _logRegContrlVrbl.wait(lock, [&] {
// return shutdown.getShutdownState() || counter.getCounter() > lastSeenCounter;
// });
//
// if (shutdown.getShutdownState()) break;
//
// lastSeenCounter = counter.getCounter();
//
// printInt(lastSeenCounter);
// std::this_thread::sleep_for(5ms);
// }
//
//}