Skip to content
This repository has been archived by the owner on Feb 3, 2025. It is now read-only.

Add mutex to make Sensor::SetActive threadsafe #2871

Merged
merged 2 commits into from
Nov 16, 2020
Merged

Conversation

iche033
Copy link
Contributor

@iche033 iche033 commented Nov 6, 2020

The IsActive function in the Sensor class is being called from various threads, e.g. rendering, physics (event callback from physics), and transport threads. So a mutex is added to protects calls for setting the active variable in Sensor class so that it is safe to call SetActive from gazebo plugins, e.g. various plugins in gazebo_ros_pkgs calls SetActive to enable / disable the sensors when subscriber count changes.

Signed-off-by: Ian Chen ichen@osrfoundation.org

Signed-off-by: Ian Chen <ichen@osrfoundation.org>
Copy link
Contributor

@ahcorde ahcorde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@chapulina chapulina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I'm just wondering if the access to active inside Sensor::Fini also needs to be protected, since that's a public function.

Signed-off-by: Ian Chen <ichen@osrfoundation.org>
@iche033
Copy link
Contributor Author

iche033 commented Nov 9, 2020

yep added mutex in Fini just in case. 59a5f75

@chapulina chapulina merged commit 5ecd18a into gazebo9 Nov 16, 2020
@chapulina chapulina deleted the lock_active branch November 16, 2020 16:27
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants