From b06ef3f3907d0edae720f95b5bd4d0b83045634b Mon Sep 17 00:00:00 2001 From: faluco Date: Wed, 24 Mar 2021 12:26:28 +0100 Subject: [PATCH] Switch the queue of the log backend to use a circular buffer. --- lib/include/srsran/common/srsran_assert.h | 3 --- .../srsran/srslog/detail/support/work_queue.h | 16 ++++++++-------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/lib/include/srsran/common/srsran_assert.h b/lib/include/srsran/common/srsran_assert.h index cef540f00..fc30241fc 100644 --- a/lib/include/srsran/common/srsran_assert.h +++ b/lib/include/srsran/common/srsran_assert.h @@ -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) diff --git a/lib/include/srsran/srslog/detail/support/work_queue.h b/lib/include/srsran/srslog/detail/support/work_queue.h index d1589f877..ef7b9d8de 100644 --- a/lib/include/srsran/srslog/detail/support/work_queue.h +++ b/lib/include/srsran/srslog/detail/support/work_queue.h @@ -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 namespace srslog { @@ -27,9 +27,9 @@ namespace detail { template class work_queue { - std::queue queue; - mutable condition_variable cond_var; - static constexpr size_t threshold = capacity * 0.98; + srsran::static_circular_buffer 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();