diff --git a/lib/include/srslte/adt/mem_pool.h b/lib/include/srslte/adt/mem_pool.h index 87066487e..d36acfe8c 100644 --- a/lib/include/srslte/adt/mem_pool.h +++ b/lib/include/srslte/adt/mem_pool.h @@ -39,6 +39,7 @@ public: // printf("head: %ld\n", (long)head); node* next = ::new (block) node(head); head = next; + count++; } uint8_t* try_pop() noexcept @@ -48,11 +49,14 @@ public: } node* last_head = head; head = head->prev; + count--; return (uint8_t*)last_head; } bool is_empty() const { return head == nullptr; } + size_t size() const { return count; } + void clear() { head = nullptr; } private: @@ -62,7 +66,8 @@ private: explicit node(node* prev_) : prev(prev_) {} }; - node* head = nullptr; + node* head = nullptr; + size_t count = 0; }; /// memblock stack that mutexes pushing/popping @@ -130,9 +135,17 @@ public: void operator()(void* block) { pool->stack.push(static_cast(block)); } single_thread_obj_pool* pool; }; - using obj_ptr = std::unique_ptr; + ~single_thread_obj_pool() + { + uint8_t* block = stack.try_pop(); + while (block != nullptr) { + delete[] block; + block = stack.try_pop(); + } + } + /// allocate object template obj_ptr make(Args&&... args) @@ -152,6 +165,8 @@ public: } } + size_t capacity() const { return stack.size(); } + private: memblock_stack stack; }; diff --git a/srsenb/src/stack/rrc/rrc.cc b/srsenb/src/stack/rrc/rrc.cc index a7a69297b..6715e0715 100644 --- a/srsenb/src/stack/rrc/rrc.cc +++ b/srsenb/src/stack/rrc/rrc.cc @@ -31,7 +31,7 @@ namespace srsenb { rrc::rrc(srslte::task_sched_handle task_sched_) : rrc_log("RRC"), task_sched(task_sched_) { pending_paging.clear(); - ue_pool.reserve(10); + ue_pool.reserve(16); } rrc::~rrc() {} @@ -151,7 +151,10 @@ void rrc::add_user(uint16_t rnti, const sched_interface::ue_cfg_t& sched_ue_cfg) bool rnti_added = true; if (rnti != SRSLTE_MRNTI) { // only non-eMBMS RNTIs are present in user map - auto p = users.insert(std::make_pair(rnti, ue_pool.make(this, rnti, sched_ue_cfg))); + auto p = users.insert(std::make_pair(rnti, ue_pool.make(this, rnti, sched_ue_cfg))); + if (ue_pool.capacity() <= 4) { + task_sched.defer_task([this]() { ue_pool.reserve(16); }); + } rnti_added = p.second and p.first->second->is_allocated(); } if (rnti_added) {