diff --git a/lib/include/srslte/common/buffer_pool.h b/lib/include/srslte/common/buffer_pool.h index d3e83acb0..bcaae9573 100644 --- a/lib/include/srslte/common/buffer_pool.h +++ b/lib/include/srslte/common/buffer_pool.h @@ -169,16 +169,13 @@ class byte_buffer_pool { public: // Singleton static methods - static std::unique_ptr instance; - static byte_buffer_pool* get_instance(int capacity = -1); - static void cleanup(); - byte_buffer_pool(int capacity = -1) { pool = new buffer_pool(capacity); } + static byte_buffer_pool* get_instance(int capacity = -1); + byte_buffer_pool(int capacity = -1) : pool(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 = nullptr, bool blocking = false) + byte_buffer_t* allocate(const char* debug_name = nullptr, bool blocking = false) { - return pool->allocate(debug_name, blocking); + return pool.allocate(debug_name, blocking); } void enable_logger(bool enabled) { print_to_log = enabled; } void deallocate(byte_buffer_t* b) @@ -187,7 +184,7 @@ public: return; } b->clear(); - if (!pool->deallocate(b)) { + if (!pool.deallocate(b)) { #ifdef SRSLTE_BUFFER_POOL_LOG_ENABLED print_error("Error deallocating PDU: Addr=0x%p, name=%s not found in pool", (void*)b, b->debug_name); #else @@ -196,7 +193,7 @@ public: } b = nullptr; } - void print_all_buffers() { pool->print_all_buffers(); } + void print_all_buffers() { pool.print_all_buffers(); } private: /// Formats and prints the input string and arguments into the configured output stream. @@ -211,8 +208,8 @@ private: } private: - bool print_to_log = false; - buffer_pool* pool; + bool print_to_log = false; + buffer_pool pool; }; inline unique_byte_buffer_t allocate_unique_buffer(byte_buffer_pool& pool, bool blocking = false) diff --git a/lib/src/common/buffer_pool.cc b/lib/src/common/buffer_pool.cc index 351268b07..f56d6f533 100644 --- a/lib/src/common/buffer_pool.cc +++ b/lib/src/common/buffer_pool.cc @@ -17,26 +17,10 @@ namespace srslte { -std::unique_ptr 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 (!instance) { - instance = std::unique_ptr(new byte_buffer_pool(capacity)); - } - pthread_mutex_unlock(&instance_mutex); + static std::unique_ptr instance(new byte_buffer_pool(capacity)); return instance.get(); } -void byte_buffer_pool::cleanup() -{ - pthread_mutex_lock(&instance_mutex); - if (instance) { - instance.reset(); - } - pthread_mutex_unlock(&instance_mutex); -} - } // namespace srslte diff --git a/lib/test/upper/pdcp_nr_test_discard_sdu.cc b/lib/test/upper/pdcp_nr_test_discard_sdu.cc index 102a3b7f8..ad35cd55d 100644 --- a/lib/test/upper/pdcp_nr_test_discard_sdu.cc +++ b/lib/test/upper/pdcp_nr_test_discard_sdu.cc @@ -75,7 +75,6 @@ int test_tx_sdu_discard(const pdcp_initial_state& init_state, */ int test_tx_discard_all(srslte::byte_buffer_pool* pool, srslte::log_ref log) { - /* * TX Test 1: PDCP Entity with SN LEN = 12 * Test TX PDU discard. @@ -108,7 +107,6 @@ int main() fprintf(stderr, "pdcp_nr_tests() failed\n"); return SRSLTE_ERROR; } - srslte::byte_buffer_pool::cleanup(); return SRSLTE_SUCCESS; } diff --git a/lib/test/upper/pdcp_nr_test_rx.cc b/lib/test/upper/pdcp_nr_test_rx.cc index 1f2bbe5ce..43e82be1e 100644 --- a/lib/test/upper/pdcp_nr_test_rx.cc +++ b/lib/test/upper/pdcp_nr_test_rx.cc @@ -24,7 +24,6 @@ int test_rx(std::vector events, srslte::log_ref log) { - srslte::pdcp_config_t cfg_rx = {1, srslte::PDCP_RB_IS_DRB, srslte::SECURITY_DIRECTION_DOWNLINK, @@ -41,7 +40,6 @@ int test_rx(std::vector events, // Generate test message and encript/decript SDU. for (pdcp_test_event_t& event : events) { - // Decript and integrity check the PDU pdcp_rx->write_pdu(std::move(event.pkt)); for (uint32_t i = 0; i < event.ticks; ++i) { @@ -237,7 +235,5 @@ int main() fprintf(stderr, "pdcp_nr_tests_rx() failed\n"); return SRSLTE_ERROR; } - srslte::byte_buffer_pool::cleanup(); - return SRSLTE_SUCCESS; } diff --git a/lib/test/upper/pdcp_nr_test_tx.cc b/lib/test/upper/pdcp_nr_test_tx.cc index 4710ecc79..2d8f882ab 100644 --- a/lib/test/upper/pdcp_nr_test_tx.cc +++ b/lib/test/upper/pdcp_nr_test_tx.cc @@ -214,7 +214,5 @@ int main() fprintf(stderr, "pdcp_nr_tests_tx() failed\n"); return SRSLTE_ERROR; } - srslte::byte_buffer_pool::cleanup(); - return SRSLTE_SUCCESS; } diff --git a/lib/test/upper/rlc_am_test.cc b/lib/test/upper/rlc_am_test.cc index a0e4d6105..48b0ce839 100644 --- a/lib/test/upper/rlc_am_test.cc +++ b/lib/test/upper/rlc_am_test.cc @@ -2060,73 +2060,61 @@ int main(int argc, char** argv) printf("basic_test failed\n"); exit(-1); }; - byte_buffer_pool::get_instance()->cleanup(); if (concat_test()) { printf("concat_test failed\n"); exit(-1); }; - byte_buffer_pool::get_instance()->cleanup(); if (segment_test(true)) { printf("segment_test with in-order PDU reception failed\n"); exit(-1); }; - byte_buffer_pool::get_instance()->cleanup(); if (segment_test(false)) { printf("segment_test with out-of-order PDU reception failed\n"); exit(-1); }; - byte_buffer_pool::get_instance()->cleanup(); if (retx_test()) { printf("retx_test failed\n"); exit(-1); }; - byte_buffer_pool::get_instance()->cleanup(); if (segment_retx_test()) { printf("segment_retx_test failed\n"); exit(-1); }; - byte_buffer_pool::get_instance()->cleanup(); if (resegment_test_1()) { printf("resegment_test_1 failed\n"); exit(-1); }; - byte_buffer_pool::get_instance()->cleanup(); if (resegment_test_2()) { printf("resegment_test_2 failed\n"); exit(-1); }; - byte_buffer_pool::get_instance()->cleanup(); if (resegment_test_3()) { printf("resegment_test_3 failed\n"); exit(-1); }; - byte_buffer_pool::get_instance()->cleanup(); if (resegment_test_4()) { printf("resegment_test_4 failed\n"); exit(-1); }; - byte_buffer_pool::get_instance()->cleanup(); if (resegment_test_5()) { printf("resegment_test_5 failed\n"); exit(-1); }; - byte_buffer_pool::get_instance()->cleanup(); if (resegment_test_6()) { printf("resegment_test_6 failed\n"); exit(-1); }; - byte_buffer_pool::get_instance()->cleanup(); rrc_log1->set_hex_limit(100); rrc_log2->set_hex_limit(100); @@ -2134,13 +2122,11 @@ int main(int argc, char** argv) printf("resegment_test_7 failed\n"); exit(-1); } - byte_buffer_pool::get_instance()->cleanup(); if (resegment_test_8()) { printf("resegment_test_8 failed\n"); exit(-1); }; - byte_buffer_pool::get_instance()->cleanup(); rrc_log1->set_hex_limit(-1); rrc_log2->set_hex_limit(-1); @@ -2148,25 +2134,21 @@ int main(int argc, char** argv) printf("reset_test failed\n"); exit(-1); }; - byte_buffer_pool::get_instance()->cleanup(); if (stop_test()) { printf("stop_test failed\n"); exit(-1); }; - byte_buffer_pool::get_instance()->cleanup(); if (resume_test()) { printf("resume_test failed\n"); exit(-1); }; - byte_buffer_pool::get_instance()->cleanup(); if (status_pdu_test()) { printf("status_pdu_test failed\n"); exit(-1); }; - byte_buffer_pool::get_instance()->cleanup(); return 0; } diff --git a/lib/test/upper/rlc_um_nr_test.cc b/lib/test/upper/rlc_um_nr_test.cc index 3f403316a..b60e56e3c 100644 --- a/lib/test/upper/rlc_um_nr_test.cc +++ b/lib/test/upper/rlc_um_nr_test.cc @@ -604,7 +604,5 @@ int main(int argc, char** argv) return SRSLTE_ERROR; } - byte_buffer_pool::get_instance()->cleanup(); - return SRSLTE_SUCCESS; } diff --git a/lib/test/upper/rlc_um_test.cc b/lib/test/upper/rlc_um_test.cc index 9dcf1f804..4af8c7f9a 100644 --- a/lib/test/upper/rlc_um_test.cc +++ b/lib/test/upper/rlc_um_test.cc @@ -435,28 +435,22 @@ int main(int argc, char** argv) if (meas_obj_test()) { return -1; } - byte_buffer_pool::get_instance()->cleanup(); if (loss_test()) { return -1; } - byte_buffer_pool::get_instance()->cleanup(); if (basic_mbsfn_test()) { return -1; } - byte_buffer_pool::get_instance()->cleanup(); if (reassmble_test()) { return -1; } - byte_buffer_pool::get_instance()->cleanup(); if (reassmble_test2()) { return -1; } - byte_buffer_pool::get_instance()->cleanup(); TESTASSERT(pdu_pack_no_space_test() == 0); - byte_buffer_pool::get_instance()->cleanup(); } diff --git a/srsue/test/upper/nas_test.cc b/srsue/test/upper/nas_test.cc index d3d22d13a..bf5e1236a 100644 --- a/srsue/test/upper/nas_test.cc +++ b/srsue/test/upper/nas_test.cc @@ -255,8 +255,6 @@ int security_command_test() } } - byte_buffer_pool::get_instance()->cleanup(); - return ret; } @@ -334,8 +332,6 @@ int mme_attach_request_test() gw.stop(); } - byte_buffer_pool::get_instance()->cleanup(); - return ret; } diff --git a/srsue/test/upper/tft_test.cc b/srsue/test/upper/tft_test.cc index efa2b0178..c9bc04089 100644 --- a/srsue/test/upper/tft_test.cc +++ b/srsue/test/upper/tft_test.cc @@ -420,5 +420,4 @@ int main(int argc, char** argv) if (tft_filter_test_ipv6_combined()) { return -1; } - srslte::byte_buffer_pool::cleanup(); }