Switch the queue of the log backend to use a circular buffer.

This commit is contained in:
faluco 2021-03-24 12:26:28 +01:00 committed by faluco
parent 8c86d2084d
commit b06ef3f390
2 changed files with 8 additions and 11 deletions

View File

@ -27,9 +27,6 @@
#define srsran_assert(condition, fmt, ...) \
do { \
if (srsran_unlikely(not(condition))) { \
srslog::fetch_basic_logger("ALL").error("%s:%d: " fmt, __FILE__, __LINE__, ##__VA_ARGS__); \
srslog::flush(); \
srsran::console_stderr("%s:%d: " fmt "\n", __FILE__, __LINE__, ##__VA_ARGS__); \
std::abort(); \
} \
} while (0)

View File

@ -13,9 +13,9 @@
#ifndef SRSLOG_DETAIL_SUPPORT_WORK_QUEUE_H
#define SRSLOG_DETAIL_SUPPORT_WORK_QUEUE_H
#include "srsran/adt/circular_buffer.h"
#include "srsran/srslog/detail/support/backend_capacity.h"
#include "srsran/srslog/detail/support/thread_utils.h"
#include <queue>
namespace srslog {
@ -27,9 +27,9 @@ namespace detail {
template <typename T, size_t capacity = SRSLOG_QUEUE_CAPACITY>
class work_queue
{
std::queue<T> queue;
mutable condition_variable cond_var;
static constexpr size_t threshold = capacity * 0.98;
srsran::static_circular_buffer<T, capacity> queue;
mutable condition_variable cond_var;
static constexpr size_t threshold = capacity * 0.98;
public:
work_queue() = default;
@ -43,7 +43,7 @@ public:
{
cond_var.lock();
// Discard the new element if we reach the maximum capacity.
if (queue.size() > capacity) {
if (queue.full()) {
cond_var.unlock();
return false;
}
@ -60,7 +60,7 @@ public:
{
cond_var.lock();
// Discard the new element if we reach the maximum capacity.
if (queue.size() > capacity) {
if (queue.full()) {
cond_var.unlock();
return false;
}
@ -81,7 +81,7 @@ public:
cond_var.wait();
}
T elem = std::move(queue.front());
T elem = std::move(queue.top());
queue.pop();
cond_var.unlock();
@ -112,7 +112,7 @@ public:
}
// Here we have been woken up normally.
T Item = std::move(queue.front());
T Item = std::move(queue.top());
queue.pop();
cond_var.unlock();