Skip to content

Commit

Permalink
Added mutex to protect stored time variables (gazebosim#2345)
Browse files Browse the repository at this point in the history
Signed-off-by: Saurabh Kamat <[email protected]>
Signed-off-by: Gaurav Kumar <[email protected]>
  • Loading branch information
sauk2 authored and GauravKumar9920 committed Mar 30, 2024
1 parent 55cd8a6 commit 2dcec27
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/systems/dvl/DopplerVelocityLogSystem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ class gz::sim::systems::DopplerVelocityLogSystem::Implementation
/// \brief Current simulation time.
public: std::chrono::steady_clock::duration nextUpdateTime{
std::chrono::steady_clock::duration::max()};

/// \brief Mutex to protect current simulation times
public: std::mutex timeMutex;
};

using namespace gz;
Expand Down Expand Up @@ -351,6 +354,8 @@ void DopplerVelocityLogSystem::Implementation::DoPostUpdate(
return true;
});

std::lock_guard<std::mutex> timeLock(this->timeMutex);

if (!this->perStepRequests.empty() || (
!_info.paused && this->nextUpdateTime <= _info.simTime))
{
Expand Down Expand Up @@ -611,6 +616,9 @@ void DopplerVelocityLogSystem::Implementation::OnRender()
}

auto closestUpdateTime = std::chrono::steady_clock::duration::max();

std::lock_guard<std::mutex> timeLock(this->timeMutex);

for (const auto & [_, sensorId] : this->sensorIdPerEntity)
{
gz::sensors::Sensor *sensor =
Expand All @@ -635,6 +643,9 @@ void DopplerVelocityLogSystem::Implementation::OnRender()
void DopplerVelocityLogSystem::Implementation::OnPostRender()
{
GZ_PROFILE("DopplerVelocityLogSystem::Implementation::OnPostRender");

std::lock_guard<std::mutex> timeLock(this->timeMutex);

for (const auto & sensorId : this->updatedSensorIds)
{
auto *sensor =
Expand Down

0 comments on commit 2dcec27

Please sign in to comment.