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

[swdev] Add API to break circular dependency with Active Object #6118

Merged
merged 1 commit into from
Mar 25, 2020

Conversation

lramati
Copy link
Contributor

@lramati lramati commented Mar 23, 2020

the new detach() function should be called on all instances of rs2::software_sensor stored inside the Active Object. This will prevent them from keeping a reference to their parent device causing the following side effects:

  1. rs2::context::get_sensor_parent will error if the instance is passed as the parameter.
  2. this instance will not keep the parent device object alive. This breaks the circular dependancy between the active object, the sensors, and the device, but also means that it is possible to attempt to use the sensor after the underlying object has been destroyed. There are no checks in the SDK to prevent this from happening and so it is entirely on the software device's developer to make sure this doesn't happen. Making sure all the threads that use the sensors are closed before the active object's destructor completes, and then making the destructor run as part of the software device's on_destruction_callback should generally be enough to prevent illegal access to the sensors.

Another note on the detach API. This API call only has an effect above the hourglass, so if you get a new reference to the sensor (for example via rs2::device::first) that one won't be detached and will keep the parent device alive. (copies of the detached instance at the cpp level will also be detached)

@dorodnic dorodnic merged commit af31294 into IntelRealSense:development Mar 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants