From a5e9c9a0276eae2b42f7630f240db7839f757591 Mon Sep 17 00:00:00 2001 From: aangerma Date: Mon, 19 Oct 2020 10:13:53 +0300 Subject: [PATCH 1/4] Fix for RS5-9071 --- src/sensor.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/sensor.cpp b/src/sensor.cpp index 7703279f1b..b7d3ea67fc 100644 --- a/src/sensor.cpp +++ b/src/sensor.cpp @@ -500,8 +500,18 @@ namespace librealsense std::lock_guard 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 (...) + { + _user_count.fetch_add( -1 ); + LOG_ERROR( "acquire_power failed " ); + throw; + } } } From 448c8ebcc4231228aa4647caa1d050cc4e4cdadc Mon Sep 17 00:00:00 2001 From: aangerma Date: Tue, 20 Oct 2020 14:36:44 +0300 Subject: [PATCH 2/4] CR fix --- src/sensor.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/sensor.cpp b/src/sensor.cpp index b7d3ea67fc..19830a8e93 100644 --- a/src/sensor.cpp +++ b/src/sensor.cpp @@ -506,6 +506,12 @@ namespace librealsense 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 ); From ba91bb99d2bb4b00ce15a38237f94afce2e6dda9 Mon Sep 17 00:00:00 2001 From: aangerma Date: Thu, 22 Oct 2020 12:20:24 +0300 Subject: [PATCH 3/4] CR fixes --- src/sensor.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/sensor.cpp b/src/sensor.cpp index 19830a8e93..2de97a645b 100644 --- a/src/sensor.cpp +++ b/src/sensor.cpp @@ -523,10 +523,22 @@ namespace librealsense void uvc_sensor::release_power() { - std::lock_guard 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 ) + { + LOG_ERROR( "release_power failed " << e.what() ); + } + catch( ... ) + { + LOG_ERROR( "release_power failed " ); + } } } From 274c73dc242afd559e9131264a60a5f2a04a8bc0 Mon Sep 17 00:00:00 2001 From: Eran Date: Thu, 22 Oct 2020 12:55:51 +0300 Subject: [PATCH 4/4] Formatting changes --- src/sensor.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/sensor.cpp b/src/sensor.cpp index 2de97a645b..7ced493d84 100644 --- a/src/sensor.cpp +++ b/src/sensor.cpp @@ -509,13 +509,13 @@ namespace librealsense catch( std::exception const & e ) { _user_count.fetch_add( -1 ); - LOG_ERROR( "acquire_power failed " << e.what() ); + LOG_ERROR( "acquire_power failed: " << e.what() ); throw; } - catch (...) + catch( ... ) { _user_count.fetch_add( -1 ); - LOG_ERROR( "acquire_power failed " ); + LOG_ERROR( "acquire_power failed" ); throw; } } @@ -530,14 +530,15 @@ namespace librealsense { _device->set_power_state( platform::D3 ); } - catch( std::exception const & e ) { - LOG_ERROR( "release_power failed " << e.what() ); + // TODO may need to change the user-count? + LOG_ERROR( "release_power failed: " << e.what() ); } catch( ... ) { - LOG_ERROR( "release_power failed " ); + // TODO may need to change the user-count? + LOG_ERROR( "release_power failed" ); } } }