mirror of https://github.com/PentHertz/srsLTE.git
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:
parent
1b1cfa40c9
commit
5bc55ec48c
|
@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue