From 2c00de1bc78aa5331283131f7bd154e790b83584 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Mon, 13 Nov 2023 10:25:14 +0100 Subject: [PATCH] Fix Data Race when updating liveliness changed in WLP (#3926) (#3960) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Refs #19702: Fix Data Race in WLP Signed-off-by: Mario Dominguez * Refs #19702: reviewer suggestion Signed-off-by: Mario Dominguez --------- Signed-off-by: Mario Dominguez (cherry picked from commit 8126a519c699e58d41c7061c2d255f98c3ef5b7b) Co-authored-by: Mario Domínguez López <116071334+Mario-DL@users.noreply.github.com> --- src/cpp/rtps/builtin/liveliness/WLP.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cpp/rtps/builtin/liveliness/WLP.cpp b/src/cpp/rtps/builtin/liveliness/WLP.cpp index 775c5ebd41e..9824f6d704f 100644 --- a/src/cpp/rtps/builtin/liveliness/WLP.cpp +++ b/src/cpp/rtps/builtin/liveliness/WLP.cpp @@ -1089,6 +1089,8 @@ void WLP::update_liveliness_changed_status( int32_t alive_change, int32_t not_alive_change) { + std::lock_guard lock(reader->getMutex()); + reader->liveliness_changed_status_.alive_count += alive_change; reader->liveliness_changed_status_.alive_count_change += alive_change; reader->liveliness_changed_status_.not_alive_count += not_alive_change;