remove byte buffer pool cleanup method and unnecessary mutexes

master
Francisco 4 years ago committed by Francisco Paisana
parent 0c7c317be5
commit 1e2153769e

@ -169,16 +169,13 @@ class byte_buffer_pool
{
public:
// Singleton static methods
static std::unique_ptr<byte_buffer_pool> instance;
static byte_buffer_pool* get_instance(int capacity = -1);
static void cleanup();
byte_buffer_pool(int capacity = -1) { pool = new buffer_pool<byte_buffer_t>(capacity); }
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)
{
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.
@ -212,7 +209,7 @@ private:
private:
bool print_to_log = false;
buffer_pool<byte_buffer_t>* pool;
buffer_pool<byte_buffer_t> pool;
};
inline unique_byte_buffer_t allocate_unique_buffer(byte_buffer_pool& pool, bool blocking = false)

@ -17,26 +17,10 @@
namespace srslte {
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 (!instance) {
instance = std::unique_ptr<byte_buffer_pool>(new byte_buffer_pool(capacity));
}
pthread_mutex_unlock(&instance_mutex);
static std::unique_ptr<byte_buffer_pool> 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

@ -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;
}

@ -24,7 +24,6 @@ int test_rx(std::vector<pdcp_test_event_t> 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<pdcp_test_event_t> 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;
}

@ -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;
}

@ -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;
}

@ -604,7 +604,5 @@ int main(int argc, char** argv)
return SRSLTE_ERROR;
}
byte_buffer_pool::get_instance()->cleanup();
return SRSLTE_SUCCESS;
}

@ -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();
}

@ -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;
}

@ -420,5 +420,4 @@ int main(int argc, char** argv)
if (tft_filter_test_ipv6_combined()) {
return -1;
}
srslte::byte_buffer_pool::cleanup();
}

Loading…
Cancel
Save