6 #ifndef SL_LOG_RECORD_QUEUE_HPP
7 #define SL_LOG_RECORD_QUEUE_HPP
14 #include <condition_variable>
18 #include <type_traits>
32 template <Record TRecord>
46 std::scoped_lock lock{ m_RecordMx };
47 m_QueuedRecords.emplace(std::move(record));
49 m_PushVar.notify_one();
61 std::optional<Record_t>
take(std::optional<std::chrono::milliseconds> waitingDuration = std::nullopt)
63 auto isQueueNotEmpty = [&records = m_QueuedRecords]() {
return !std::empty(records); };
65 std::unique_lock lock{ m_RecordMx };
68 if (m_PushVar.wait_for(lock, *waitingDuration, isQueueNotEmpty))
70 return takeNextAsOpt();
75 m_PushVar.wait(lock, isQueueNotEmpty);
76 return takeNextAsOpt();
87 std::scoped_lock lock{ m_RecordMx };
88 return std::empty(m_QueuedRecords);
97 std::size_t
size() const noexcept
99 std::scoped_lock lock{ m_RecordMx };
100 return std::size(m_QueuedRecords);
105 std::optional<Record_t> takeNextAsOpt()
107 auto record = std::move(m_QueuedRecords.front());
108 m_QueuedRecords.pop();
109 return std::optional<Record_t>{ std::in_place, std::move(record) };
112 mutable std::mutex m_RecordMx;
113 std::queue<Record_t> m_QueuedRecords;
114 std::condition_variable m_PushVar;
Storage for Record s.
Definition: RecordQueue.hpp:34
std::size_t size() const noexcept
Checks size of the internal queue.
Definition: RecordQueue.hpp:97
std::optional< Record_t > take(std::optional< std::chrono::milliseconds > waitingDuration=std::nullopt)
Takes the first Record from the queue.
Definition: RecordQueue.hpp:61
void push(Record_t record)
Pushes Record s to the internal queue.
Definition: RecordQueue.hpp:43
std::remove_cvref_t< TRecord > Record_t
Definition: RecordQueue.hpp:36
bool empty() const noexcept
Checks if the internal queue is empty.
Definition: RecordQueue.hpp:85
Definition: BasicSink.hpp:22