diff --git a/lib/include/srslte/common/buffer_pool.h b/lib/include/srslte/common/buffer_pool.h index eee04caa8..8a2e50b77 100644 --- a/lib/include/srslte/common/buffer_pool.h +++ b/lib/include/srslte/common/buffer_pool.h @@ -56,8 +56,12 @@ class buffer_pool{ public: // non-static methods - buffer_pool(uint32_t nof_buffers = POOL_SIZE) + buffer_pool(int capacity_ = -1) { + uint32_t nof_buffers = POOL_SIZE; + if (capacity > 0) { + nof_buffers = (uint32_t) capacity_; + } pthread_mutex_init(&mutex, NULL); for(uint32_t i=0;i; + byte_buffer_pool(int capacity = -1) { + pool = new buffer_pool(capacity); } ~byte_buffer_pool() { delete pool; @@ -178,7 +182,9 @@ public: return; } b->reset(); - pool->deallocate(b); + if (!pool->deallocate(b)) { + fprintf(stderr, "Error deallocating PDU: Addr=0x%lx not found in pool\n", (uint64_t) b); + } b = NULL; } void print_all_buffers() { diff --git a/lib/src/common/buffer_pool.cc b/lib/src/common/buffer_pool.cc index 3bb191143..cfe8d56a5 100644 --- a/lib/src/common/buffer_pool.cc +++ b/lib/src/common/buffer_pool.cc @@ -35,11 +35,13 @@ namespace srslte{ byte_buffer_pool *byte_buffer_pool::instance = NULL; pthread_mutex_t instance_mutex = PTHREAD_MUTEX_INITIALIZER; -byte_buffer_pool* byte_buffer_pool::get_instance(void) +byte_buffer_pool* byte_buffer_pool::get_instance(int capacity) { pthread_mutex_lock(&instance_mutex); - if(NULL == instance) - instance = new byte_buffer_pool(); + if(NULL == instance) { + printf("Creating buffer pool capacity=%d\n", capacity); + instance = new byte_buffer_pool(capacity); + } pthread_mutex_unlock(&instance_mutex); return instance; } diff --git a/srsenb/hdr/enb.h b/srsenb/hdr/enb.h index 93e9436d9..b483d021b 100644 --- a/srsenb/hdr/enb.h +++ b/srsenb/hdr/enb.h @@ -173,6 +173,8 @@ public: private: static enb *instance; + const static int ENB_POOL_SIZE = 1024*10; + enb(); virtual ~enb(); diff --git a/srsenb/src/enb.cc b/srsenb/src/enb.cc index 3b41672a0..f1e237568 100644 --- a/srsenb/src/enb.cc +++ b/srsenb/src/enb.cc @@ -55,7 +55,7 @@ void enb::cleanup(void) enb::enb() : started(false) { srslte_dft_load(); - pool = srslte::byte_buffer_pool::get_instance(); + pool = srslte::byte_buffer_pool::get_instance(ENB_POOL_SIZE); logger = NULL; args = NULL;