From c08b720ecf3d7bf643a78eabba7a85830e123b1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Gonz=C3=A1lez?= Date: Thu, 12 Aug 2021 16:35:55 +0200 Subject: [PATCH] Fix calculation next_payload when more than one loop (#2117) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ricardo González Moreno (cherry picked from commit 19d54eb52cf24c2888ed8c776674821a1c6b7186) --- src/cpp/rtps/DataSharing/ReaderPool.hpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/cpp/rtps/DataSharing/ReaderPool.hpp b/src/cpp/rtps/DataSharing/ReaderPool.hpp index 8c1b9db7bdd..d15b3e7bfd4 100644 --- a/src/cpp/rtps/DataSharing/ReaderPool.hpp +++ b/src/cpp/rtps/DataSharing/ReaderPool.hpp @@ -233,14 +233,18 @@ class ReaderPool : public DataSharingPayloadPool bool ensure_reading_reference_is_in_bounds() { - if ((next_payload_ >> 32) < (descriptor_->notified_end >> 32) && - static_cast(next_payload_) <= static_cast(descriptor_->notified_end)) + auto notified_end = end(); + auto notified_end_high = notified_end >> 32; + auto next_payload_high = next_payload_ >> 32; + if (next_payload_high + 1 < notified_end_high || + (next_payload_high < notified_end_high && + static_cast(next_payload_) <= static_cast(notified_end))) { logWarning(RTPS_READER, "Writer " << writer() << " overtook reader in datasharing pool." << " Some changes will be missing."); // lower part is the index, upper part is the loop counter - next_payload_ = ((next_payload_ >> 32) << 32) + static_cast(descriptor_->notified_end); + next_payload_ = ((notified_end_high - 1) << 32) + static_cast(notified_end); advance(next_payload_); return false; }