Changed discard_if to appyly_if in circular_buffer.h.

This was done so it would work when circular buffer holds other things
that are not unique_pointers. Queue and pop_func had to be made public
to be able to call the pop_func when an SDU is discarded.
This commit is contained in:
Pedro Alvarez 2021-03-23 13:01:48 +00:00
parent 1b1cfa40c9
commit 5bc55ec48c
3 changed files with 24 additions and 23 deletions

View File

@ -207,16 +207,14 @@ public:
const_iterator end() const { return const_iterator(*this, (rpos + count) % max_size()); }
template <typename F>
T discard_if(const F& func)
bool apply_first(const F& func)
{
for (auto it = begin(); it != end(); it++) {
if (*it != nullptr && func(*it)) {
T tmp = std::move(*it);
*it = nullptr;
return tmp;
if (func(*it)) {
return true;
}
}
return nullptr;
return false;
}
protected:
@ -334,24 +332,20 @@ public:
}
template <typename F>
bool discard_if(const F& func)
bool apply_first(const F& func)
{
std::lock_guard<std::mutex> lock(mutex);
T tmp = circ_buffer.discard_if(func);
if (tmp == nullptr) {
return false;
}
pop_func(tmp);
return true;
return circ_buffer.apply_first(func);
}
PushingFunc push_func;
PoppingFunc pop_func;
protected:
bool active = true;
uint8_t nof_waiting = 0;
mutable std::mutex mutex;
std::condition_variable cvar_empty, cvar_full;
PushingFunc push_func;
PoppingFunc pop_func;
CircBuffer circ_buffer;
~base_blocking_queue() { stop(); }
@ -596,9 +590,9 @@ public:
void set_size(size_t size) { base_t::circ_buffer.set_size(size); }
template <typename F>
bool discard_if(const F& func)
bool apply_first(const F& func)
{
return base_t::discard_if(func);
return base_t::apply_first(func);
}
};

View File

@ -73,9 +73,9 @@ public:
bool is_full() { return queue.full(); }
template <typename F>
bool discard_if(const F& func)
bool apply_first(const F& func)
{
return queue.discard_if(func);
return queue.apply_first(func);
}
private:
@ -105,9 +105,11 @@ private:
uint32_t* n_sdus;
};
uint32_t unread_bytes = 0;
uint32_t n_sdus = 0;
public:
dyn_blocking_queue<unique_byte_buffer_t, push_callback, pop_callback> queue;
uint32_t unread_bytes = 0;
uint32_t n_sdus = 0;
};
} // namespace srsran

View File

@ -454,8 +454,13 @@ void rlc_am_lte::rlc_am_lte_tx::discard_sdu(uint32_t discard_sn)
return;
}
bool discarded =
tx_sdu_queue.discard_if([&discard_sn](const unique_byte_buffer_t& sdu) { return sdu->md.pdcp_sn == discard_sn; });
bool discarded = tx_sdu_queue.apply_first([&discard_sn, this](unique_byte_buffer_t& sdu) {
if (sdu != nullptr && sdu->md.pdcp_sn == discard_sn) {
tx_sdu_queue.queue.pop_func(sdu);
sdu = nullptr;
}
return false;
});
if (discarded) {
// remove also from undelivered SDUs queue