added growth policy for rrc::ue memory pool. Fixed memory leak

master
Francisco Paisana 4 years ago
parent a73cbcdc9d
commit 768a4fa627

@ -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<uint8_t*>(block)); }
single_thread_obj_pool<T>* pool;
};
using obj_ptr = std::unique_ptr<T, obj_deleter>;
~single_thread_obj_pool()
{
uint8_t* block = stack.try_pop();
while (block != nullptr) {
delete[] block;
block = stack.try_pop();
}
}
/// allocate object
template <typename... Args>
obj_ptr make(Args&&... args)
@ -152,6 +165,8 @@ public:
}
}
size_t capacity() const { return stack.size(); }
private:
memblock_stack stack;
};

@ -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) {

Loading…
Cancel
Save