From 5c16b98370793eaa65e6151f3fbc542c45b7c0e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Gonz=C3=A1lez=20Moreno?= Date: Mon, 11 Sep 2023 14:28:03 +0200 Subject: [PATCH] Refs #19254. Apply suggestions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ricardo González Moreno --- src/cpp/fastdds/publisher/DataWriterHistory.cpp | 1 - src/cpp/rtps/history/History.cpp | 9 +++++++++ src/cpp/rtps/history/WriterHistory.cpp | 10 ++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/cpp/fastdds/publisher/DataWriterHistory.cpp b/src/cpp/fastdds/publisher/DataWriterHistory.cpp index 8ad7b3bb912..c8d025a4257 100644 --- a/src/cpp/fastdds/publisher/DataWriterHistory.cpp +++ b/src/cpp/fastdds/publisher/DataWriterHistory.cpp @@ -369,7 +369,6 @@ bool DataWriterHistory::remove_change_pub( return false; } #else - static_cast(max_blocking_time); std::lock_guard guard(*this->mp_mutex); #endif // if HAVE_STRICT_REALTIME diff --git a/src/cpp/rtps/history/History.cpp b/src/cpp/rtps/history/History.cpp index 0b340faee02..1c3e0324657 100644 --- a/src/cpp/rtps/history/History.cpp +++ b/src/cpp/rtps/history/History.cpp @@ -112,7 +112,16 @@ bool History::remove_change( CacheChange_t* ch, const std::chrono::time_point& max_blocking_time) { +#if HAVE_STRICT_REALTIME + std::unique_lock lock(*mp_mutex, std::defer_lock); + if (!lock.try_lock_until(max_blocking_time)) + { + EPROSIMA_LOG_ERROR(PUBLISHER, "Cannot lock the DataWriterHistory mutex"); + return false; + } +#else std::lock_guard guard(*mp_mutex); +#endif // if HAVE_STRICT_REALTIME const_iterator it = find_change_nts(ch); const_iterator end_it = changesEnd(); diff --git a/src/cpp/rtps/history/WriterHistory.cpp b/src/cpp/rtps/history/WriterHistory.cpp index fc99e4e459e..2fcf0ae1e44 100644 --- a/src/cpp/rtps/history/WriterHistory.cpp +++ b/src/cpp/rtps/history/WriterHistory.cpp @@ -287,7 +287,17 @@ bool WriterHistory::remove_min_change( return false; } +#if HAVE_STRICT_REALTIME + std::unique_lock lock(*mp_mutex, std::defer_lock); + if (!lock.try_lock_until(max_blocking_time)) + { + EPROSIMA_LOG_ERROR(PUBLISHER, "Cannot lock the DataWriterHistory mutex"); + return false; + } +#else std::lock_guard guard(*mp_mutex); +#endif // if HAVE_STRICT_REALTIME + if (m_changes.size() > 0 && remove_change_g(m_changes.front(), max_blocking_time)) { return true;