From 1f73e6ae69262cd2a01cbdd7091552c15ddd8557 Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Thu, 4 Jun 2020 21:28:28 +0200 Subject: [PATCH] multiqueue: add option to create queue with non-default capacity this allows to create a queue that has a non-default capacity currently this is 8192, but the value might now be suitable in some cases like for TTI sync events --- lib/include/srslte/common/multiqueue.h | 30 ++++++++++++++++++++++---- lib/test/common/queue_test.cc | 22 +++++++++++++++++++ srsenb/sib.conf.example | 6 +++--- 3 files changed, 51 insertions(+), 7 deletions(-) diff --git a/lib/include/srslte/common/multiqueue.h b/lib/include/srslte/common/multiqueue.h index 8c3181e7f..aca551341 100644 --- a/lib/include/srslte/common/multiqueue.h +++ b/lib/include/srslte/common/multiqueue.h @@ -38,6 +38,8 @@ namespace srslte { +#define MULTIQUEUE_DEFAULT_CAPACITY (8192) // Default per-queue capacity + template class multiqueue_handler { @@ -106,7 +108,7 @@ public: int queue_id = -1; }; - explicit multiqueue_handler(uint32_t capacity_ = 8192) : capacity(capacity_) {} + explicit multiqueue_handler(uint32_t capacity_ = MULTIQUEUE_DEFAULT_CAPACITY) : capacity(capacity_) {} ~multiqueue_handler() { reset(); } void reset() @@ -125,7 +127,12 @@ public: queues.clear(); } - int add_queue() + /** + * Adds a new queue with fixed capacity + * @param capacity_ The capacity of the queue. + * @return The index of the newly created (or reused) queue within the vector of queues. + */ + int add_queue(uint32_t capacity_) { uint32_t qidx = 0; std::lock_guard lock(mutex); @@ -134,15 +141,24 @@ public: } for (; qidx < queues.size() and queues[qidx].active; ++qidx) ; - if (qidx == queues.size()) { + + // check if there is a free queue of the required size + if (qidx == queues.size() || queues[qidx].capacity() != capacity_) { // create new queue - queues.emplace_back(capacity); + queues.emplace_back(capacity_); + qidx = queues.size() - 1; // update qidx to the last element } else { queues[qidx].active = true; } return (int)qidx; } + /** + * Add queue using the default capacity of the underlying multiqueue + * @return The queue index + */ + int add_queue() { return add_queue(capacity); } + int nof_queues() { std::lock_guard lock(mutex); @@ -247,6 +263,12 @@ public: return queues[qidx].size(); } + size_t max_size(int qidx) + { + std::lock_guard lck(mutex); + return queues[qidx].capacity(); + } + const myobj& front(int qidx) { std::lock_guard lck(mutex); diff --git a/lib/test/common/queue_test.cc b/lib/test/common/queue_test.cc index 17c6ce8e6..dc1b50a32 100644 --- a/lib/test/common/queue_test.cc +++ b/lib/test/common/queue_test.cc @@ -96,6 +96,28 @@ int test_multiqueue() TESTASSERT(multiqueue.size(qid2) == 5) TESTASSERT(multiqueue.wait_pop(&number) == qid2 and number == 30) + // remove existing queues + multiqueue.erase_queue(qid1); + multiqueue.erase_queue(qid2); + TESTASSERT(multiqueue.nof_queues() == 0) + + // check that adding a queue of different capacity works + { + int qid1 = multiqueue.add_queue(); + int qid2 = multiqueue.add_queue(); + + // remove first queue again + multiqueue.erase_queue(qid1); + TESTASSERT(multiqueue.nof_queues() == 1) + + // add queue with non-default capacity + int qid3 = multiqueue.add_queue(10); + + // make sure neither a new queue index is returned + TESTASSERT(qid1 != qid3) + TESTASSERT(qid2 != qid3) + } + std::cout << "outcome: Success\n"; std::cout << "===========================================\n"; diff --git a/srsenb/sib.conf.example b/srsenb/sib.conf.example index 253d4dc4d..b111c3cce 100644 --- a/srsenb/sib.conf.example +++ b/srsenb/sib.conf.example @@ -101,9 +101,9 @@ sib2 = { t300 = 2000; // in ms t301 = 100; // in ms - t310 = 1000; // in ms + t310 = 200; // in ms n310 = 1; - t311 = 1000; // in ms + t311 = 10000; // in ms n311 = 1; }; @@ -153,4 +153,4 @@ sib7 = band_ind = "dcs1800"; } ); -}; \ No newline at end of file +};