AP_HAL_SITL: introduce get_HAL_mutable() to complement get_HAL()

Returns a mutable reference to the same HAL for certain purposes where
the HAL needs to be mutated to avoid UB problems with casting away const
and to make the fact that mutation is happening obvious.
This commit is contained in:
Thomas Watson 2023-11-23 19:56:54 -06:00 committed by Peter Barker
parent 8fe95dca81
commit 3c82ac6043
1 changed files with 8 additions and 3 deletions

View File

@ -33,7 +33,7 @@
using namespace HALSITL;
HAL_SITL& hal_sitl = (HAL_SITL&)AP_HAL::get_HAL();
HAL_SITL& hal_sitl = (HAL_SITL&)AP_HAL::get_HAL_mutable();
static Storage sitlStorage;
static SITL_State sitlState;
@ -299,9 +299,14 @@ void HAL_SITL::actually_reboot()
AP_HAL::panic("PANIC: REBOOT FAILED: %s", strerror(errno));
}
static HAL_SITL hal_sitl_inst;
const AP_HAL::HAL& AP_HAL::get_HAL() {
static const HAL_SITL hal;
return hal;
return hal_sitl_inst;
}
AP_HAL::HAL& AP_HAL::get_HAL_mutable() {
return hal_sitl_inst;
}
#endif // CONFIG_HAL_BOARD == HAL_BOARD_SITL