Skip to content

Commit

Permalink
Reset cache changes to avoid data fragmentation issues (#9)
Browse files Browse the repository at this point in the history
* Reset cache change que return to pool

Signed-off-by: jparisu <javierparis@eprosima.com>

* Reset the serialized payload and the inline QoS

Signed-off-by: tempate <danieldiaz@eprosima.com>

* Uncrustify

Signed-off-by: tempate <danieldiaz@eprosima.com>

* Include what you use

Signed-off-by: tempate <danieldiaz@eprosima.com>

* Remove virtual keyword from methods that override

Signed-off-by: tempate <danieldiaz@eprosima.com>

---------

Signed-off-by: jparisu <javierparis@eprosima.com>
Signed-off-by: tempate <danieldiaz@eprosima.com>
Co-authored-by: tempate <danieldiaz@eprosima.com>
  • Loading branch information
jparisu and Tempate authored Jun 5, 2024
1 parent ef2e6c1 commit e97bdc1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#pragma once

#include <fastdds/rtps/common/CacheChange.h>
#include <fastdds/rtps/history/IChangePool.h>

#include <cpp_utils/pool/UnboundedPool.hpp>
Expand Down Expand Up @@ -45,18 +46,21 @@ class CacheChangePool : public fastrtps::rtps::IChangePool, public utils::Unboun
utils::PoolConfiguration configuration);

//! Call UnboundedPool::reserve
virtual bool reserve_cache(
bool reserve_cache(
fastrtps::rtps::CacheChange_t*& cache_change) override;

//! Call UnboundedPool::release
virtual bool release_cache(
bool release_cache(
fastrtps::rtps::CacheChange_t* cache_change) override;

protected:

//! Override the UnboundedPool::create_element method to create a RouterCacheChange object.
virtual fastrtps::rtps::CacheChange_t* new_element_() override;
fastrtps::rtps::CacheChange_t* new_element_() override;

//! Override the IPool::reset_element_ method to reset the CacheChange as a new object.
void reset_element_(
fastrtps::rtps::CacheChange_t* change) override;
};

} /* namespace core */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <efficiency/cache_change/CacheChangePool.hpp>
#include <types/dds/RouterCacheChange.hpp>
#include <fastrtps/rtps/common/Guid.h>
#include <fastdds/rtps/common/ChangeKind_t.hpp>

#include <ddspipe_participants/efficiency/cache_change/CacheChangePool.hpp>
#include <ddspipe_participants/types/dds/RouterCacheChange.hpp>

namespace eprosima {
namespace ddspipe {
Expand Down Expand Up @@ -43,6 +46,24 @@ fastrtps::rtps::CacheChange_t* CacheChangePool::new_element_()
return new types::RouterCacheChange();
}

void CacheChangePool::reset_element_(
fastrtps::rtps::CacheChange_t* change)
{
// NOTE: This could be done by =operator but it is deleted, so it must be done field by field
change->kind = fastrtps::rtps::ALIVE;
change->sequenceNumber.high = 0;
change->sequenceNumber.low = 0;
change->writerGUID = fastrtps::rtps::c_Guid_Unknown;
change->instanceHandle.clear();
change->isRead = 0;
change->sourceTimestamp.seconds(0);
change->sourceTimestamp.fraction(0);
change->writer_info.num_sent_submessages = 0;
change->setFragmentSize(0);
change->serializedPayload.empty();
change->inline_qos.empty();
}

} /* namespace core */
} /* namespace ddspipe */
} /* namespace eprosima */

0 comments on commit e97bdc1

Please sign in to comment.