mirror of https://github.com/PentHertz/srsLTE.git
stack optimization - optimization of the multiqueue
avoid notifying the consumer side of the multiqueue of a new pushed object, if the multiqueue already knows that the queue is not empty.
This commit is contained in:
parent
d574afcd33
commit
d947e259c9
|
@ -73,6 +73,7 @@ class multiqueue_handler
|
|||
return;
|
||||
}
|
||||
active_ = val;
|
||||
consumer_notify_needed = true;
|
||||
|
||||
if (not active_) {
|
||||
buffer.clear();
|
||||
|
@ -112,10 +113,12 @@ class multiqueue_handler
|
|||
{
|
||||
std::unique_lock<std::mutex> lock(q_mutex);
|
||||
if (buffer.empty()) {
|
||||
consumer_notify_needed = true;
|
||||
return false;
|
||||
}
|
||||
obj = std::move(buffer.top());
|
||||
buffer.pop();
|
||||
consumer_notify_needed = false;
|
||||
if (nof_waiting > 0) {
|
||||
lock.unlock();
|
||||
cv_full.notify_one();
|
||||
|
@ -141,7 +144,14 @@ class multiqueue_handler
|
|||
}
|
||||
buffer.push(std::forward<T>(*o));
|
||||
}
|
||||
if (consumer_notify_needed) {
|
||||
// Note: The consumer thread only needs to be notified and awaken when queues transition from empty to non-empty
|
||||
// To ensure that the consumer noticed that the queue was empty before a push, we store the last
|
||||
// try_pop() return in a member variable.
|
||||
// Doing this reduces the contention of multiple producers for the same condition variable
|
||||
parent->cv_empty.notify_one();
|
||||
consumer_notify_needed = false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -151,6 +161,7 @@ class multiqueue_handler
|
|||
srsran::dyn_circular_buffer<myobj> buffer;
|
||||
std::condition_variable cv_full, cv_exit;
|
||||
bool active_ = true;
|
||||
bool consumer_notify_needed = true;
|
||||
int nof_waiting = 0;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue