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.
master
Pedro Alvarez 4 years ago
parent 1b1cfa40c9
commit 5bc55ec48c

@ -207,16 +207,14 @@ public:
const_iterator end() const { return const_iterator(*this, (rpos + count) % max_size()); } const_iterator end() const { return const_iterator(*this, (rpos + count) % max_size()); }
template <typename F> template <typename F>
T discard_if(const F& func) bool apply_first(const F& func)
{ {
for (auto it = begin(); it != end(); it++) { for (auto it = begin(); it != end(); it++) {
if (*it != nullptr && func(*it)) { if (func(*it)) {
T tmp = std::move(*it); return true;
*it = nullptr;
return tmp;
} }
} }
return nullptr; return false;
} }
protected: protected:
@ -334,24 +332,20 @@ public:
} }
template <typename F> template <typename F>
bool discard_if(const F& func) bool apply_first(const F& func)
{ {
std::lock_guard<std::mutex> lock(mutex); std::lock_guard<std::mutex> lock(mutex);
T tmp = circ_buffer.discard_if(func); return circ_buffer.apply_first(func);
if (tmp == nullptr) {
return false;
}
pop_func(tmp);
return true;
} }
PushingFunc push_func;
PoppingFunc pop_func;
protected: protected:
bool active = true; bool active = true;
uint8_t nof_waiting = 0; uint8_t nof_waiting = 0;
mutable std::mutex mutex; mutable std::mutex mutex;
std::condition_variable cvar_empty, cvar_full; std::condition_variable cvar_empty, cvar_full;
PushingFunc push_func;
PoppingFunc pop_func;
CircBuffer circ_buffer; CircBuffer circ_buffer;
~base_blocking_queue() { stop(); } ~base_blocking_queue() { stop(); }
@ -596,9 +590,9 @@ public:
void set_size(size_t size) { base_t::circ_buffer.set_size(size); } void set_size(size_t size) { base_t::circ_buffer.set_size(size); }
template <typename F> 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(); } bool is_full() { return queue.full(); }
template <typename F> 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: private:
@ -105,9 +105,11 @@ private:
uint32_t* n_sdus; uint32_t* n_sdus;
}; };
dyn_blocking_queue<unique_byte_buffer_t, push_callback, pop_callback> queue;
uint32_t unread_bytes = 0; uint32_t unread_bytes = 0;
uint32_t n_sdus = 0; uint32_t n_sdus = 0;
public:
dyn_blocking_queue<unique_byte_buffer_t, push_callback, pop_callback> queue;
}; };
} // namespace srsran } // namespace srsran

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

Loading…
Cancel
Save