Skip to content

Commit

Permalink
PR #7604 from Avishag: Handle exception in uvc_sensor::acquire_power …
Browse files Browse the repository at this point in the history
…(RS5-9071)
  • Loading branch information
maloel authored Oct 22, 2020
2 parents 21450ec + 274c73d commit aed6b0a
Showing 1 changed file with 34 additions and 5 deletions.
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;
}
}
}

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

0 comments on commit aed6b0a

Please sign in to comment.