Skip to content

Commit

Permalink
PR #13347 from OhadMeir: Some Coverity issues fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
OhadMeir authored Sep 15, 2024
2 parents c8ca380 + a6ed5ce commit 618d88f
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 17 deletions.
6 changes: 6 additions & 0 deletions common/notifications.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,12 @@ namespace rs2
_log += line + "\n";
}

const std::string process_manager::get_log() const
{
std::lock_guard< std::mutex > lock( _log_lock );
return _log;
}

void process_manager::reset()
{
_progress = 0;
Expand Down
4 changes: 2 additions & 2 deletions common/notifications.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ namespace rs2
bool done() const { return _done; }
bool started() const { return _started; }
bool failed() const { return _failed; }
const std::string& get_log() const { return _log; }
const std::string get_log() const;
void reset();

void check_error(std::string& error) { if (_failed) error = _last_error; }
Expand All @@ -141,7 +141,7 @@ namespace rs2
bool _failed = false;
float _progress = 0;

std::mutex _log_lock;
mutable std::mutex _log_lock;
std::string _last_error;
std::string _process_name;
};
Expand Down
1 change: 1 addition & 0 deletions src/core/notification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ void notifications_processor::set_callback( rs2_notifications_callback_sptr call

rs2_notifications_callback_sptr notifications_processor::get_callback() const
{
std::lock_guard< std::mutex > lock( _callback_mutex );
return _callback;
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/notification.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class notifications_processor

private:
rs2_notifications_callback_sptr _callback;
std::mutex _callback_mutex;
mutable std::mutex _callback_mutex;
dispatcher _dispatcher;
};

Expand Down
3 changes: 2 additions & 1 deletion src/global_timestamp_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,9 @@ namespace librealsense
{
LOG_DEBUG("time_diff_keeper::stop: stop object.");
_active_object.stop();
_coefs.reset();
_is_ready = false;
std::lock_guard< std::recursive_mutex > lock( _read_mtx );
_coefs.reset();
}
}

Expand Down
1 change: 1 addition & 0 deletions src/hid-sensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ void hid_sensor::start( rs2_frame_callback_sptr callback )
_hid_device->start_capture(
[this, last_frame_number, last_timestamp]( const platform::sensor_data & sensor_data ) mutable
{
std::lock_guard< std::mutex > lock( _configure_lock );
const auto system_time = time_service::get_time(); // time frame was received from the backend
auto timestamp_reader = _hid_iio_timestamp_reader.get();
static const std::string custom_sensor_name = "custom";
Expand Down
15 changes: 9 additions & 6 deletions src/media/playback/playback_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,12 +380,14 @@ void playback_device::resume()
return;

auto total_duration = m_reader->query_duration();
if (m_last_published_timestamp >= total_duration)
m_last_published_timestamp = device_serializer::nanoseconds(0);
m_reader->reset();
m_reader->seek_to_time(m_last_published_timestamp);
while (m_last_published_timestamp != device_serializer::nanoseconds(0) && !m_reader->read_next_data()->is<serialized_frame>());

{
std::lock_guard< std::mutex > locker( m_last_published_timestamp_mutex );
if( m_last_published_timestamp >= total_duration )
m_last_published_timestamp = device_serializer::nanoseconds(0);
m_reader->reset();
m_reader->seek_to_time(m_last_published_timestamp);
while (m_last_published_timestamp != device_serializer::nanoseconds(0) && !m_reader->read_next_data()->is<serialized_frame>());
}
m_is_paused = false;
catch_up();

Expand Down Expand Up @@ -560,6 +562,7 @@ void playback_device::do_loop(T action)
}
}

std::lock_guard<std::mutex> locker(m_last_published_timestamp_mutex);
m_last_published_timestamp = device_serializer::nanoseconds(0);
}

Expand Down
4 changes: 2 additions & 2 deletions src/pipeline/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ namespace librealsense

config(const config& other)
{
std::lock_guard< std::mutex > lock( other._mtx ); // So other configuration won't change while reading (streams enabled/disabled)
_device_request = other._device_request;
_stream_requests = other._stream_requests;
_enable_all_streams = other._enable_all_streams;
_stream_requests = other._stream_requests;
_resolved_profile = nullptr;
_playback_loop = other._playback_loop;
}
Expand All @@ -57,7 +57,7 @@ namespace librealsense

device_request _device_request;
std::map<std::pair<rs2_stream, int>, stream_profile> _stream_requests;
std::mutex _mtx;
mutable std::mutex _mtx;
bool _enable_all_streams = false;
std::shared_ptr<profile> _resolved_profile;
bool _playback_loop = false;
Expand Down
1 change: 0 additions & 1 deletion src/proc/hole-filling-filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ namespace librealsense
<< "Unsupported mode for hole filling selected: value " << val
<< " is out of range." );

std::lock_guard<std::mutex> lock(_mutex);
_hole_filling_mode = static_cast<uint8_t>(val);
});

Expand Down
2 changes: 0 additions & 2 deletions src/proc/temporal-filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ namespace librealsense
depth_processing_block("Temporal Filter"),
_persistence_param(persistence_default),
_alpha_param(temp_alpha_default),
_one_minus_alpha(1- _alpha_param),
_delta_param(temp_delta_default),
_width(0), _height(0), _stride(0), _bpp(0),
_extension_type(RS2_EXTENSION_DEPTH_FRAME),
Expand Down Expand Up @@ -146,7 +145,6 @@ namespace librealsense
{
std::lock_guard<std::mutex> lock(_mutex);
_alpha_param = val;
_one_minus_alpha = 1.f - _alpha_param;
_cur_frame_index = 0;
_last_frame.clear();
_history.clear();
Expand Down
6 changes: 4 additions & 2 deletions src/proc/temporal-filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ namespace librealsense

unsigned char mask = 1 << _cur_frame_index;

// Copy locally, to remove need for a lock.
float alpha = _alpha_param;
float one_minus_alpha = 1.f - alpha;
// pass one -- go through image and update all
for (size_t i = 0; i < _current_frm_size_pixels; i++)
{
Expand All @@ -53,7 +56,7 @@ namespace librealsense
if (diff < delta_z)
{ // old and new val agree
history[i] |= mask;
float filtered = _alpha_param * cur_val + _one_minus_alpha * prev_val;
float filtered = alpha * cur_val + one_minus_alpha * prev_val;
T result = static_cast<T>(filtered);
frame[i] = result;
_last_frame[i] = result;
Expand Down Expand Up @@ -92,7 +95,6 @@ namespace librealsense
uint8_t _persistence_param;

float _alpha_param; // The normalized weight of the current pixel
float _one_minus_alpha;
uint8_t _delta_param; // A threshold when a filter is invoked
size_t _width, _height, _stride;
size_t _bpp;
Expand Down

0 comments on commit 618d88f

Please sign in to comment.