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
master
Andre Puschmann 4 years ago
parent d1cb5531d6
commit 1f73e6ae69

@ -38,6 +38,8 @@
namespace srslte {
#define MULTIQUEUE_DEFAULT_CAPACITY (8192) // Default per-queue capacity
template <typename myobj>
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<std::mutex> 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<std::mutex> lock(mutex);
@ -247,6 +263,12 @@ public:
return queues[qidx].size();
}
size_t max_size(int qidx)
{
std::lock_guard<std::mutex> lck(mutex);
return queues[qidx].capacity();
}
const myobj& front(int qidx)
{
std::lock_guard<std::mutex> lck(mutex);

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

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

Loading…
Cancel
Save