Skip to content

Commit

Permalink
options-watcher queries option before starting thread
Browse files Browse the repository at this point in the history
  • Loading branch information
OhadMeir committed Dec 24, 2023
1 parent 5fa97e6 commit 6730ac6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
15 changes: 6 additions & 9 deletions src/core/options-watcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,7 @@ options_watcher::~options_watcher()

void options_watcher::register_option( rs2_option id, std::shared_ptr< option > option )
{
registered_option opt = { option, 0.0f };
try
{
opt.last_known_value = option->query();
}
catch( ... )
{
// Some options cannot be queried all the time (i.e. streaming only)
}
registered_option opt = { option, 0.0f }; //Option actual value will be queried in start if needed.

{
std::lock_guard< std::mutex > lock( _mutex );
Expand Down Expand Up @@ -84,6 +76,11 @@ void options_watcher::start()
{
if( ! _updater.joinable() ) // If not already started
{
if( _should_query_for_first_time )
{
update_options();
_should_query_for_first_time = false;
}
_updater = std::thread( [this]() { thread_loop(); } );
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/core/options-watcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,15 @@ class options_watcher

struct registered_option
{
std::shared_ptr< option > sptr = std::shared_ptr< option >( nullptr );
std::shared_ptr< option > sptr;
float last_known_value = 0.0f;
};
std::map< rs2_option, registered_option > _options;
rsutils::signal< const std::map< rs2_option, std::shared_ptr< option > > & > _on_values_changed;
std::chrono::milliseconds _update_interval;
std::thread _updater;
std::mutex _mutex;
bool _should_query_for_first_time = true;
};


Expand Down

0 comments on commit 6730ac6

Please sign in to comment.