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

Handle exception in uvc_sensor::acquire_power #7604

Merged
merged 4 commits into from
Oct 22, 2020
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
39 changes: 34 additions & 5 deletions src/sensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -500,17 +500,46 @@ namespace librealsense
std::lock_guard<std::mutex> lock(_power_lock);
if (_user_count.fetch_add(1) == 0)
{
_device->set_power_state(platform::D0);
for (auto&& xu : _xus) _device->init_xu(xu);
try
{
_device->set_power_state( platform::D0 );
for( auto && xu : _xus )
_device->init_xu( xu );
}
catch( std::exception const & e )
{
_user_count.fetch_add( -1 );
LOG_ERROR( "acquire_power failed: " << e.what() );
throw;
}
catch( ... )
{
_user_count.fetch_add( -1 );
LOG_ERROR( "acquire_power failed" );
throw;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

What about void uvc_sensor::release_power() below - could the fix be applicable there as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Its not needed because the fix is for the cases that release_power() didn't call because of exception on acquire_power().

Copy link
Collaborator

Choose a reason for hiding this comment

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

But is it possible that setting D3 would throw?

}
}

void uvc_sensor::release_power()
{
std::lock_guard<std::mutex> lock(_power_lock);
if (_user_count.fetch_add(-1) == 1)
std::lock_guard< std::mutex > lock( _power_lock );
if( _user_count.fetch_add( -1 ) == 1 )
{
_device->set_power_state(platform::D3);
try
{
_device->set_power_state( platform::D3 );
}
catch( std::exception const & e )
{
// TODO may need to change the user-count?
LOG_ERROR( "release_power failed: " << e.what() );
}
catch( ... )
{
// TODO may need to change the user-count?
LOG_ERROR( "release_power failed" );
}
}
}

Expand Down