mirror of https://github.com/PentHertz/srsLTE.git
multiqueue bugfix for non-blocking pushes when queue is full
This commit is contained in:
parent
adcfcfe012
commit
996d8ef74d
|
@ -133,15 +133,23 @@ class multiqueue_handler
|
|||
bool push_(T* o, bool blocking) noexcept
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(q_mutex);
|
||||
while (active_ and blocking and buffer.full()) {
|
||||
nof_waiting++;
|
||||
cv_full.wait(lock);
|
||||
nof_waiting--;
|
||||
}
|
||||
if (not active_) {
|
||||
lock.unlock();
|
||||
cv_exit.notify_one();
|
||||
return false;
|
||||
if (not blocking) {
|
||||
// non-blocking case
|
||||
if (not active_ or buffer.full()) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
// blocking case
|
||||
while (active_ and buffer.full()) {
|
||||
nof_waiting++;
|
||||
cv_full.wait(lock);
|
||||
nof_waiting--;
|
||||
}
|
||||
if (not active_) {
|
||||
lock.unlock();
|
||||
cv_exit.notify_one();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
buffer.push(std::forward<T>(*o));
|
||||
if (consumer_notify_needed) {
|
||||
|
|
|
@ -240,7 +240,7 @@ int test_multiqueue_threading4()
|
|||
auto qid3 = multiqueue.add_queue();
|
||||
auto qid4 = multiqueue.add_queue();
|
||||
std::mutex mutex;
|
||||
int last_number;
|
||||
int last_number = -1;
|
||||
auto pop_blocking_func = [&multiqueue, &last_number, &mutex](bool* success) {
|
||||
int number = 0;
|
||||
while (multiqueue.wait_pop(&number)) {
|
||||
|
|
Loading…
Reference in New Issue