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
11
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
20void 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
30void 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
41{
42 const std::lock_guard<std::mutex> lock(m_mutex);
43 return m_queue.empty();
44}
45
47{
48 const std::lock_guard<std::mutex> lock(m_mutex);
49 return m_queue.size();
50}
51
52void Term::Private::BlockingQueue::wait_for_events(std::unique_lock<std::mutex>& lock) { m_cv.wait(lock); }
void push(const Term::Event &value, const std::size_t &occurrence=1)
void wait_for_events(std::unique_lock< std::mutex > &lock)
std::queue< Term::Event > m_queue