4#include "proto/service.pb.h"
5#include <condition_variable>
23 LogQueue(uint64_t queueMaxSize) : queueMaxSize(queueMaxSize), stopped(false) {
24 queue.reserve(queueMaxSize);
37 std::unique_lock<std::mutex> lock(queueMutex);
41 if (queue.size() >= queueMaxSize)
44 queue.emplace_back(item);
56 bool fetch_all(std::vector<proto::LogEntry *> &refFetchedItems) {
58 std::unique_lock<std::mutex> lock(queueMutex);
62 refFetchedItems = std::move(queue);
66 cvInsert.notify_all();
76 std::unique_lock<std::mutex> lock(queueMutex);
80 cvInsert.notify_all();
90 std::vector<proto::LogEntry *> queue;
91 uint64_t queueMaxSize;
92 std::mutex queueMutex;
93 std::condition_variable cvInsert;
A queue for storing log entries with thread-safe operations.
Definition log_queue.h:17
void stop()
Stops the queue. This will unblock all waiting threads and prevent further operations.
Definition log_queue.h:74
bool fetch_all(std::vector< proto::LogEntry * > &refFetchedItems)
Fetches all log entries from the queue.
Definition log_queue.h:56
bool is_stopped()
Checks if the queue has been stopped.
Definition log_queue.h:87
bool insert(proto::LogEntry *item)
Inserts a log entry into the queue. If the queue is full, it replaces the last item in the queue....
Definition log_queue.h:35
LogQueue(uint64_t queueMaxSize)
Definition log_queue.h:23
Definition access_point.cpp:22