cpp-terminal
1.0.0
Small C++ library for writing multiplatform terminal applications
Loading...
Searching...
No Matches
blocking_queue.cpp
Go to the documentation of this file.
1
/*
2
* cpp-terminal
3
* C++ library for writing multi-platform terminal applications.
4
*
5
* SPDX-FileCopyrightText: 2019-2024 cpp-terminal
6
*
7
* SPDX-License-Identifier: MIT
8
*/
9
10
#include "
cpp-terminal/private/blocking_queue.hpp
"
11
12
Term::Event
Term::Private::BlockingQueue::pop
()
13
{
14
const
std::lock_guard<std::mutex> lock(
m_mutex
);
15
Term::Event
value = this->
m_queue
.front();
16
m_queue
.pop();
17
return
value;
18
}
19
20
void
Term::Private::BlockingQueue::push
(
const
Term::Event
& value,
const
std::size_t& occurrence)
21
{
22
for
(std::size_t i = 0; i != occurrence; ++i)
23
{
24
const
std::lock_guard<std::mutex> lock(m_mutex);
25
m_queue.push(value);
26
m_cv.notify_all();
27
}
28
}
29
30
void
Term::Private::BlockingQueue::push
(
const
Term::Event
&& value,
const
std::size_t& occurrence)
31
{
32
for
(std::size_t i = 0; i != occurrence; ++i)
33
{
34
const
std::lock_guard<std::mutex> lock(m_mutex);
35
m_queue.push(value);
36
m_cv.notify_all();
37
}
38
}
39
40
bool
Term::Private::BlockingQueue::empty
()
41
{
42
const
std::lock_guard<std::mutex> lock(m_mutex);
43
return
m_queue.empty();
44
}
45
46
std::size_t
Term::Private::BlockingQueue::size
()
47
{
48
const
std::lock_guard<std::mutex> lock(m_mutex);
49
return
m_queue.size();
50
}
51
52
void
Term::Private::BlockingQueue::wait_for_events
(std::unique_lock<std::mutex>& lock) { m_cv.wait(lock); }
blocking_queue.hpp
Term::Event
Definition
event.hpp:25
Term::Private::BlockingQueue::size
std::size_t size()
Definition
blocking_queue.cpp:46
Term::Private::BlockingQueue::push
void push(const Term::Event &value, const std::size_t &occurrence=1)
Definition
blocking_queue.cpp:20
Term::Private::BlockingQueue::empty
bool empty()
Definition
blocking_queue.cpp:40
Term::Private::BlockingQueue::wait_for_events
void wait_for_events(std::unique_lock< std::mutex > &lock)
Definition
blocking_queue.cpp:52
Term::Private::BlockingQueue::pop
Term::Event pop()
Definition
blocking_queue.cpp:12
Term::Private::BlockingQueue::m_mutex
std::mutex m_mutex
Definition
blocking_queue.hpp:41
Term::Private::BlockingQueue::m_queue
std::queue< Term::Event > m_queue
Definition
blocking_queue.hpp:42
cpp-terminal
private
blocking_queue.cpp
Generated by
1.11.0