Skip to content

Commit 37028f7

Browse files
authored
PR #13613 from Eran: optimize rs2_get_options_list with bulk operation
2 parents 5b1ea01 + 1bba476 commit 37028f7

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

src/rs.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -920,6 +920,9 @@ HANDLE_EXCEPTIONS_AND_RETURN( , options, option_value )
920920
rs2_options_list* rs2_get_options_list(const rs2_options* options, rs2_error** error) BEGIN_API_CALL
921921
{
922922
VALIDATE_NOT_NULL(options);
923+
rsutils::deferred bulk_op;
924+
if( auto sensor = dynamic_cast<sensor_base *>(options->options) )
925+
bulk_op = sensor->bulk_operation();
923926
auto rs2_list = new rs2_options_list;
924927
auto option_ids = options->options->get_supported_options();
925928
rs2_list->list.reserve( option_ids.size() );

src/sensor.h

+15-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// License: Apache 2.0. See LICENSE file in root directory.
2-
// Copyright(c) 2015 Intel Corporation. All Rights Reserved.
2+
// Copyright(c) 2015-24 Intel Corporation. All Rights Reserved.
33
#pragma once
44

55
#include "core/sensor-interface.h"
@@ -13,6 +13,7 @@
1313

1414
#include <rsutils/lazy.h>
1515
#include <rsutils/signal.h>
16+
#include <rsutils/deferred.h>
1617

1718
#include <chrono>
1819
#include <memory>
@@ -90,6 +91,16 @@ namespace librealsense
9091
return {};
9192
}
9293

94+
// Sometimes it is more efficient to prepare for large or repeating operations. Depending on the actual sensor
95+
// type we might want to change power state or encapsulate small transactions into a large one.
96+
virtual void prepare_for_bulk_operation() {}
97+
virtual void finished_bulk_operation() {}
98+
rsutils::deferred bulk_operation()
99+
{
100+
prepare_for_bulk_operation();
101+
return rsutils::deferred( [this] { finished_bulk_operation(); } );
102+
}
103+
93104
// recordable< recommended_proccesing_blocks_interface > is needed to record our recommended processing blocks
94105
public:
95106
void enable_recording( std::function< void( const recommended_proccesing_blocks_interface & ) > ) override {}
@@ -196,11 +207,6 @@ namespace librealsense
196207

197208
std::shared_ptr< std::map< uint32_t, rs2_format > > & get_fourcc_to_rs2_format_map();
198209
std::shared_ptr< std::map< uint32_t, rs2_stream > > & get_fourcc_to_rs2_stream_map();
199-
200-
// Sometimes it is more efficient to prepare for large or repeating operations. Depending on the actual sensor
201-
// type we might want to change power state or encapsulate small transactions into a large one.
202-
virtual void prepare_for_bulk_operation() {}
203-
virtual void finished_bulk_operation(){}
204210
};
205211

206212
// A sensor pointer to another "raw sensor", usually UVC/HID
@@ -254,6 +260,9 @@ namespace librealsense
254260
virtual void register_option_to_update( rs2_option id, std::shared_ptr< option > option );
255261
virtual void unregister_option_from_update( rs2_option id );
256262

263+
void prepare_for_bulk_operation() override { _raw_sensor->prepare_for_bulk_operation(); }
264+
void finished_bulk_operation() override { _raw_sensor->finished_bulk_operation(); }
265+
257266
private:
258267
void register_processing_block_options(const processing_block& pb);
259268
void unregister_processing_block_options(const processing_block& pb);

0 commit comments

Comments
 (0)