Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added mutex to protect stored time variables #2345

Merged
merged 1 commit into from
Mar 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading