From 5d676199ab7641b4379d10ec154fb4fc3888c404 Mon Sep 17 00:00:00 2001 From: Francisco Date: Fri, 19 Mar 2021 13:40:48 +0000 Subject: [PATCH] adt bugfix - fix copy/move ctor of circular map --- lib/include/srsran/adt/circular_map.h | 50 +++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/lib/include/srsran/adt/circular_map.h b/lib/include/srsran/adt/circular_map.h index 441dd913d..04a3b0cc3 100644 --- a/lib/include/srsran/adt/circular_map.h +++ b/lib/include/srsran/adt/circular_map.h @@ -82,6 +82,52 @@ public: size_t idx = 0; }; + static_circular_map() { std::fill(present.begin(), present.end(), false); } + static_circular_map(const static_circular_map& other) : present(other.present), count(other.count) + { + for (size_t idx = 0; idx < other.size(); ++idx) { + if (present[idx]) { + new (&buffer[idx]) obj_t(other.get_obj_(idx)); + } + } + } + static_circular_map(static_circular_map&& other) noexcept : present(other.present), count(other.count) + { + for (size_t idx = 0; idx < other.size(); ++idx) { + if (present[idx]) { + new (&buffer[idx]) obj_t(std::move(other.get_obj_(idx))); + } + } + other.clear(); + } + ~static_circular_map() { clear(); } + static_circular_map& operator=(const static_circular_map& other) + { + if (this == &other) { + return *this; + } + clear(); + count = other.count; + present = other.present; + for (size_t idx = 0; idx < other.size(); ++idx) { + if (present[idx]) { + new (&buffer[idx]) obj_t(other.get_obj_(idx)); + } + } + } + static_circular_map& operator=(static_circular_map&& other) noexcept + { + clear(); + count = other.count; + present = other.present; + for (size_t idx = 0; idx < other.size(); ++idx) { + if (present[idx]) { + new (&buffer[idx]) obj_t(std::move(other.get_obj_(idx))); + } + } + clear(); + } + bool contains(K id) { size_t idx = id % N; @@ -182,8 +228,8 @@ private: const obj_t& get_obj_(size_t idx) const { return reinterpret_cast(buffer[idx]); } std::array buffer; - std::array present = {false}; - size_t count = 0; + std::array present; + size_t count = 0; }; } // namespace srsran