diff --git a/include/fastrtps/rtps/writer/StatelessWriter.h b/include/fastrtps/rtps/writer/StatelessWriter.h index 16425c3cc0a..26db5ce3b97 100644 --- a/include/fastrtps/rtps/writer/StatelessWriter.h +++ b/include/fastrtps/rtps/writer/StatelessWriter.h @@ -102,7 +102,7 @@ class StatelessWriter : public RTPSWriter */ inline size_t getMatchedReadersSize() const {return m_matched_readers.size();}; - bool clean_history(unsigned int /*max = 0*/){ return false; } + bool clean_history(unsigned int max = 0); private: //Duration_t resendDataPeriod; //FIXME: Not used yet. diff --git a/src/cpp/rtps/writer/StatelessWriter.cpp b/src/cpp/rtps/writer/StatelessWriter.cpp index ab6386c3e23..b2765b1871c 100644 --- a/src/cpp/rtps/writer/StatelessWriter.cpp +++ b/src/cpp/rtps/writer/StatelessWriter.cpp @@ -352,7 +352,31 @@ void StatelessWriter::unsent_changes_reset() //} +bool StatelessWriter::clean_history(unsigned int max) +{ + boost::lock_guard guard(*mp_mutex); + + bool removed = false; + if (max == 0) { + max = mp_history->getHistorySize(); + } + + while (max--) { + CacheChange_t *cc; + if (!mp_history->get_min_change(&cc)) { + break; + } + if (mp_history->remove_change(cc)) { + removed = true; + } + } + if (removed) { + unsent_changes_reset(); + } + + return removed; +}