From bb7053d9eedede9c2d57d376877c92af6a7aaa42 Mon Sep 17 00:00:00 2001 From: Thad House Date: Thu, 23 Feb 2023 00:59:59 -0800 Subject: [PATCH] [hal] Fix HAL_GetRuntimeType being slow on the roboRIO (#5130) HAL_GetRuntimeType used to be a free call before the roboRIO2 was added. However, nLoadOut::getTargetClass() is not a free call, and it may hit the IPC layer. Cache this value so it is not called every time. --- hal/src/main/native/athena/HAL.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/hal/src/main/native/athena/HAL.cpp b/hal/src/main/native/athena/HAL.cpp index c2ed275de7..eda229af95 100644 --- a/hal/src/main/native/athena/HAL.cpp +++ b/hal/src/main/native/athena/HAL.cpp @@ -253,12 +253,10 @@ const char* HAL_GetErrorMessage(int32_t code) { } } +static HAL_RuntimeType runtimeType = HAL_Runtime_RoboRIO; + HAL_RuntimeType HAL_GetRuntimeType(void) { - nLoadOut::tTargetClass targetClass = nLoadOut::getTargetClass(); - if (targetClass == nLoadOut::kTargetClass_RoboRIO2) { - return HAL_Runtime_RoboRIO2; - } - return HAL_Runtime_RoboRIO; + return runtimeType; } int32_t HAL_GetFPGAVersion(int32_t* status) { @@ -523,6 +521,13 @@ HAL_Bool HAL_Initialize(int32_t timeout, int32_t mode) { return false; } + nLoadOut::tTargetClass targetClass = nLoadOut::getTargetClass(); + if (targetClass == nLoadOut::kTargetClass_RoboRIO2) { + runtimeType = HAL_Runtime_RoboRIO2; + } else { + runtimeType = HAL_Runtime_RoboRIO; + } + InterruptManager::Initialize(global->getSystemInterface()); hal::InitializeDriverStation();