From ca7fe1349ea753c79ff0c6217967897cce4e985f Mon Sep 17 00:00:00 2001 From: Francisco Date: Fri, 12 Mar 2021 13:13:20 +0000 Subject: [PATCH] remove unnecessary sfinae from bounded_vector. Use bounded_vector for UE cc buffers. Set ue cc used buffers remove_pdu method to private --- lib/include/srslte/adt/bounded_vector.h | 37 +++++++++++++------------ srsenb/hdr/stack/mac/ue.h | 6 ++-- srsenb/src/stack/mac/ue.cc | 9 +++--- 3 files changed, 27 insertions(+), 25 deletions(-) diff --git a/lib/include/srslte/adt/bounded_vector.h b/lib/include/srslte/adt/bounded_vector.h index fd121d6d8..0a0997d12 100644 --- a/lib/include/srslte/adt/bounded_vector.h +++ b/lib/include/srslte/adt/bounded_vector.h @@ -30,19 +30,12 @@ public: using value_type = T; bounded_vector() = default; - template ::value, int>::type = 0> - explicit bounded_vector(size_type N) - { - append(N); - } - template ::value, int>::type = 0> - bounded_vector(size_type N, const U& init_val) - { - append(N, T(init_val)); - } + explicit bounded_vector(size_type N) { append(N); } + bounded_vector(size_type N, const T& val) { append(N, val); } bounded_vector(const bounded_vector& other) { append(other.begin(), other.end()); } bounded_vector(bounded_vector&& other) noexcept { + static_assert(std::is_move_constructible::value, "T must be move-constructible"); std::uninitialized_copy(std::make_move_iterator(other.begin()), std::make_move_iterator(other.end()), end()); size_ = other.size(); other.clear(); @@ -114,13 +107,13 @@ public: } T& front() { return (*this)[0]; } const T& front() const { return (*this)[0]; } - T* data() { return reinterpret_cast(&buffer[0]); } - const T* data() const { return reinterpret_cast(&buffer[0]); } + T* data() { return &front(); } + const T* data() const { return &front(); } // Iterators - iterator begin() { return reinterpret_cast(&buffer[0]); } + iterator begin() { return data(); } iterator end() { return begin() + size_; } - const_iterator begin() const { return reinterpret_cast(&buffer[0]); } + const_iterator begin() const { return data(); } const_iterator end() const { return begin() + size_; } // Capacity @@ -159,19 +152,22 @@ public: } void push_back(const T& value) { + static_assert(std::is_copy_constructible::value, "T must be copy-constructible"); size_++; assert(size_ <= MAX_N); new (&back()) T(value); } void push_back(T&& value) { + static_assert(std::is_move_constructible::value, "T must be move-constructible"); size_++; assert(size_ <= MAX_N); new (&back()) T(std::move(value)); } template - typename std::enable_if::value>::type emplace_back(Args&&... args) + void emplace_back(Args&&... args) { + static_assert(std::is_constructible::value, "Passed arguments to emplace_back are invalid"); size_++; assert(size_ <= MAX_N); new (&back()) T(std::forward(args)...); @@ -182,9 +178,14 @@ public: back().~T(); size_--; } - typename std::enable_if::value>::type resize(size_type count) { resize(count, T()); } - void resize(size_type count, const T& value) + void resize(size_type count) { + static_assert(std::is_default_constructible::value, "T must be default constructible"); + resize(count, T()); + } + void resize(size_type count, const T& value) + { + static_assert(std::is_copy_constructible::value, "T must be copy constructible"); if (size_ > count) { destroy(begin() + count, end()); size_ = count; @@ -215,12 +216,14 @@ private: } void append(size_type N, const T& element) { + static_assert(std::is_copy_constructible::value, "T must be copy-constructible"); assert(N + size_ <= MAX_N); std::uninitialized_fill_n(end(), N, element); size_ += N; } void append(size_type N) { + static_assert(std::is_default_constructible::value, "T must be default-constructible"); assert(N + size_ <= MAX_N); for (size_type i = size_; i < size_ + N; ++i) { new (&buffer[i]) T(); diff --git a/srsenb/hdr/stack/mac/ue.h b/srsenb/hdr/stack/mac/ue.h index ea6ab45ea..421801fdf 100644 --- a/srsenb/hdr/stack/mac/ue.h +++ b/srsenb/hdr/stack/mac/ue.h @@ -45,8 +45,6 @@ public: void clear_old_pdus(tti_point current_tti); - void remove_pdu(tti_point tti); - bool try_deallocate_pdu(tti_point tti); void clear(); @@ -56,6 +54,8 @@ public: bool has_tti(tti_point tti) const; private: + void remove_pdu(tti_point tti); + srslog::basic_logger* logger; srslte::pdu_queue* shared_pdu_queue; @@ -183,7 +183,7 @@ private: int nof_rx_harq_proc = 0; int nof_tx_harq_proc = 0; - std::vector cc_buffers; + srslte::bounded_vector cc_buffers; std::mutex rx_buffers_mutex; diff --git a/srsenb/src/stack/mac/ue.cc b/srsenb/src/stack/mac/ue.cc index d93eb40ca..51a446982 100644 --- a/srsenb/src/stack/mac/ue.cc +++ b/srsenb/src/stack/mac/ue.cc @@ -210,7 +210,6 @@ ue::ue(uint16_t rnti_, nof_tx_harq_proc(nof_tx_harq_proc_), ta_fsm(this) { - cc_buffers.reserve(nof_cells_); for (size_t i = 0; i < nof_cells_; ++i) { cc_buffers.emplace_back(pdus); } @@ -255,7 +254,7 @@ srslte_softbuffer_rx_t* ue::get_rx_softbuffer(const uint32_t ue_cc_idx, const ui return nullptr; } - return &cc_buffers.at(ue_cc_idx).get_rx_softbuffer(tti % nof_rx_harq_proc); + return &cc_buffers[ue_cc_idx].get_rx_softbuffer(tti % nof_rx_harq_proc); } srslte_softbuffer_tx_t* @@ -274,7 +273,7 @@ uint8_t* ue::request_buffer(uint32_t tti, uint32_t ue_cc_idx, const uint32_t len std::unique_lock lock(rx_buffers_mutex); uint8_t* pdu = nullptr; if (len > 0) { - pdu = cc_buffers.at(ue_cc_idx).get_rx_used_buffers().request_pdu(tti_point(tti), len); + pdu = cc_buffers[ue_cc_idx].get_rx_used_buffers().request_pdu(tti_point(tti), len); } else { logger.error("UE buffers: Requesting buffer for zero bytes"); } @@ -422,7 +421,7 @@ void ue::process_pdu(uint8_t* pdu, uint32_t nof_bytes, srslte::pdu_queue::channe void ue::deallocate_pdu(uint32_t tti, uint32_t ue_cc_idx) { std::unique_lock lock(rx_buffers_mutex); - if (not cc_buffers.at(ue_cc_idx).get_rx_used_buffers().try_deallocate_pdu(tti_point(tti))) { + if (not cc_buffers[ue_cc_idx].get_rx_used_buffers().try_deallocate_pdu(tti_point(tti))) { logger.warning("UE buffers: Null RX PDU pointer in deallocate_pdu for rnti=0x%x pid=%d cc_idx=%d", rnti, tti % nof_rx_harq_proc, @@ -433,7 +432,7 @@ void ue::deallocate_pdu(uint32_t tti, uint32_t ue_cc_idx) void ue::push_pdu(uint32_t tti, uint32_t ue_cc_idx, uint32_t len) { std::unique_lock lock(rx_buffers_mutex); - if (not cc_buffers.at(ue_cc_idx).get_rx_used_buffers().push_pdu(tti_point(tti), len)) { + if (not cc_buffers[ue_cc_idx].get_rx_used_buffers().push_pdu(tti_point(tti), len)) { logger.warning( "UE buffers: Failed to push RX PDU for rnti=0x%x pid=%d cc_idx=%d", rnti, tti % nof_rx_harq_proc, ue_cc_idx); }