mirror of https://github.com/PentHertz/srsLTE.git
- Fixed a leak in the MME class not releasing the static byte buffer pool.
- Now the pool gets destroyed on program exit using a unique_ptr. - Removed manual cleanup() calls in all the code base to free the pool instance.
This commit is contained in:
parent
dcf5a727f2
commit
f0d651ae8e
|
@ -58,8 +58,8 @@ public:
|
|||
if (capacity_ > 0) {
|
||||
nof_buffers = (uint32_t)capacity_;
|
||||
}
|
||||
pthread_mutex_init(&mutex, NULL);
|
||||
pthread_cond_init(&cv_not_empty, NULL);
|
||||
pthread_mutex_init(&mutex, nullptr);
|
||||
pthread_cond_init(&cv_not_empty, nullptr);
|
||||
for (uint32_t i = 0; i < nof_buffers; i++) {
|
||||
buffer_t* b = new buffer_t;
|
||||
available.push(b);
|
||||
|
@ -101,10 +101,10 @@ public:
|
|||
|
||||
bool is_almost_empty() { return available.size() < capacity / 20; }
|
||||
|
||||
buffer_t* allocate(const char* debug_name = NULL, bool blocking = false)
|
||||
buffer_t* allocate(const char* debug_name = nullptr, bool blocking = false)
|
||||
{
|
||||
pthread_mutex_lock(&mutex);
|
||||
buffer_t* b = NULL;
|
||||
buffer_t* b = nullptr;
|
||||
|
||||
if (available.size() > 0) {
|
||||
b = available.top();
|
||||
|
@ -172,18 +172,18 @@ class byte_buffer_pool
|
|||
{
|
||||
public:
|
||||
// Singleton static methods
|
||||
static byte_buffer_pool* instance;
|
||||
static std::unique_ptr<byte_buffer_pool> instance;
|
||||
static byte_buffer_pool* get_instance(int capacity = -1);
|
||||
static void cleanup(void);
|
||||
static void cleanup();
|
||||
byte_buffer_pool(int capacity = -1)
|
||||
{
|
||||
log = NULL;
|
||||
log = nullptr;
|
||||
pool = new buffer_pool<byte_buffer_t>(capacity);
|
||||
}
|
||||
byte_buffer_pool(const byte_buffer_pool& other) = delete;
|
||||
byte_buffer_pool& operator=(const byte_buffer_pool& other) = delete;
|
||||
~byte_buffer_pool() { delete pool; }
|
||||
byte_buffer_t* allocate(const char* debug_name = NULL, bool blocking = false)
|
||||
byte_buffer_t* allocate(const char* debug_name = nullptr, bool blocking = false)
|
||||
{
|
||||
return pool->allocate(debug_name, blocking);
|
||||
}
|
||||
|
@ -209,7 +209,7 @@ public:
|
|||
#endif
|
||||
}
|
||||
}
|
||||
b = NULL;
|
||||
b = nullptr;
|
||||
}
|
||||
void print_all_buffers() { pool->print_all_buffers(); }
|
||||
|
||||
|
|
|
@ -26,25 +26,24 @@
|
|||
|
||||
namespace srslte {
|
||||
|
||||
byte_buffer_pool* byte_buffer_pool::instance = NULL;
|
||||
pthread_mutex_t instance_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
std::unique_ptr<byte_buffer_pool> byte_buffer_pool::instance;
|
||||
static pthread_mutex_t instance_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
byte_buffer_pool* byte_buffer_pool::get_instance(int capacity)
|
||||
{
|
||||
pthread_mutex_lock(&instance_mutex);
|
||||
if (NULL == instance) {
|
||||
instance = new byte_buffer_pool(capacity);
|
||||
if (!instance) {
|
||||
instance = std::unique_ptr<byte_buffer_pool>(new byte_buffer_pool(capacity));
|
||||
}
|
||||
pthread_mutex_unlock(&instance_mutex);
|
||||
return instance;
|
||||
return instance.get();
|
||||
}
|
||||
|
||||
void byte_buffer_pool::cleanup(void)
|
||||
void byte_buffer_pool::cleanup()
|
||||
{
|
||||
pthread_mutex_lock(&instance_mutex);
|
||||
if (NULL != instance) {
|
||||
delete instance;
|
||||
instance = NULL;
|
||||
if (instance) {
|
||||
instance.reset();
|
||||
}
|
||||
pthread_mutex_unlock(&instance_mutex);
|
||||
}
|
||||
|
|
|
@ -117,6 +117,5 @@ int nas_dedicated_eps_bearer_context_setup_request_test()
|
|||
int main(int argc, char** argv)
|
||||
{
|
||||
int result = nas_dedicated_eps_bearer_context_setup_request_test();
|
||||
srslte::byte_buffer_pool::cleanup();
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -172,7 +172,6 @@ int main()
|
|||
fprintf(stderr, "pdcp_nr_tests_rx() failed\n");
|
||||
return SRSLTE_ERROR;
|
||||
}
|
||||
srslte::byte_buffer_pool::cleanup();
|
||||
|
||||
return SRSLTE_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -206,5 +206,4 @@ int main(int argc, char** argv)
|
|||
if (meas_obj_test()) {
|
||||
return -1;
|
||||
}
|
||||
byte_buffer_pool::get_instance()->cleanup();
|
||||
}
|
||||
|
|
|
@ -560,7 +560,6 @@ int main(int argc, char** argv)
|
|||
}
|
||||
|
||||
stress_test(args);
|
||||
byte_buffer_pool::get_instance()->cleanup();
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
|
|
@ -40,9 +40,7 @@ enb::enb() : started(false), pool(srslte::byte_buffer_pool::get_instance(ENB_POO
|
|||
|
||||
enb::~enb()
|
||||
{
|
||||
// pool has to be cleaned after enb is deleted
|
||||
stack.reset();
|
||||
srslte::byte_buffer_pool::cleanup();
|
||||
}
|
||||
|
||||
int enb::init(const all_args_t& args_, srslte::logger* logger_)
|
||||
|
|
|
@ -48,9 +48,7 @@ ue::ue() : logger(nullptr)
|
|||
|
||||
ue::~ue()
|
||||
{
|
||||
// destruct stack components before cleaning buffer pool
|
||||
stack.reset();
|
||||
byte_buffer_pool::cleanup();
|
||||
}
|
||||
|
||||
int ue::init(const all_args_t& args_, srslte::logger* logger_)
|
||||
|
|
|
@ -404,8 +404,6 @@ int esm_info_request_test()
|
|||
}
|
||||
}
|
||||
|
||||
pool->cleanup();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -486,8 +484,6 @@ int dedicated_eps_bearer_test()
|
|||
nas.get_metrics(&metrics);
|
||||
TESTASSERT(metrics.nof_active_eps_bearer == 1);
|
||||
|
||||
pool->cleanup();
|
||||
|
||||
return SRSLTE_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
|
@ -322,5 +322,4 @@ int main(int argc, char** argv)
|
|||
if (tft_filter_test_ipv4_tos()) {
|
||||
return -1;
|
||||
}
|
||||
srslte::byte_buffer_pool::cleanup();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue