From 63282002c9e79251083f92f7bbc49428986de4de Mon Sep 17 00:00:00 2001 From: Akash Date: Fri, 2 Jul 2021 11:03:40 -0500 Subject: [PATCH] Fixes for windows (#443) * Fix building on windows * Fix MSVC linker error when building tests * Fix hang when loading controller on windows * Use better log for configuring controller * Be consistent with visibility control * Use try_lock throw exception on failure --- controller_manager/src/controller_manager.cpp | 14 ++++++++++---- .../test/test_controller/test_controller.hpp | 1 + .../include/fake_components/generic_system.hpp | 3 ++- .../hardware_interface/resource_manager.hpp | 2 +- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/controller_manager/src/controller_manager.cpp b/controller_manager/src/controller_manager.cpp index 15fb0ce91d..db21eb6466 100644 --- a/controller_manager/src/controller_manager.cpp +++ b/controller_manager/src/controller_manager.cpp @@ -890,7 +890,7 @@ void ControllerManager::configure_controller_service_cb( RCLCPP_DEBUG( get_logger(), "configuring service called for controller '%s' ", request->name.c_str()); std::lock_guard guard(services_lock_); - RCLCPP_DEBUG(get_logger(), "loading service locked"); + RCLCPP_DEBUG(get_logger(), "configuring service locked"); response->ok = configure_controller(request->name) == controller_interface::return_type::OK; @@ -1153,7 +1153,9 @@ ControllerManager::RTControllerListWrapper::update_and_get_used_by_rt_list() std::vector & ControllerManager::RTControllerListWrapper::get_unused_list( const std::lock_guard &) { - assert(controllers_lock_.try_lock()); + if (!controllers_lock_.try_lock()) { + throw std::runtime_error("controllers_lock_ not owned by thread"); + } controllers_lock_.unlock(); // Get the index to the outdated controller list int free_controllers_list = get_other_list(updated_controllers_index_); @@ -1166,7 +1168,9 @@ std::vector & ControllerManager::RTControllerListWrapper::get_un const std::vector & ControllerManager::RTControllerListWrapper::get_updated_list( const std::lock_guard &) const { - assert(controllers_lock_.try_lock()); + if (!controllers_lock_.try_lock()) { + throw std::runtime_error("controllers_lock_ not owned by thread"); + } controllers_lock_.unlock(); return controllers_lists_[updated_controllers_index_]; } @@ -1174,7 +1178,9 @@ const std::vector & ControllerManager::RTControllerListWrapper:: void ControllerManager::RTControllerListWrapper::switch_updated_list( const std::lock_guard &) { - assert(controllers_lock_.try_lock()); + if (!controllers_lock_.try_lock()) { + throw std::runtime_error("controllers_lock_ not owned by thread"); + } controllers_lock_.unlock(); int former_current_controllers_list_ = updated_controllers_index_; updated_controllers_index_ = get_other_list(former_current_controllers_list_); diff --git a/controller_manager/test/test_controller/test_controller.hpp b/controller_manager/test/test_controller/test_controller.hpp index 4b5a9985be..308088b70c 100644 --- a/controller_manager/test/test_controller/test_controller.hpp +++ b/controller_manager/test/test_controller/test_controller.hpp @@ -62,6 +62,7 @@ class TestController : public controller_interface::ControllerInterface rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn on_cleanup(const rclcpp_lifecycle::State & previous_state) override; + CONTROLLER_MANAGER_PUBLIC void set_command_interface_configuration( const controller_interface::InterfaceConfiguration & cfg); diff --git a/hardware_interface/include/fake_components/generic_system.hpp b/hardware_interface/include/fake_components/generic_system.hpp index 9105395c14..7d78d30738 100644 --- a/hardware_interface/include/fake_components/generic_system.hpp +++ b/hardware_interface/include/fake_components/generic_system.hpp @@ -33,7 +33,8 @@ using hardware_interface::return_type; namespace fake_components { -class GenericSystem : public hardware_interface::BaseInterface +class HARDWARE_INTERFACE_PUBLIC GenericSystem + : public hardware_interface::BaseInterface { public: return_type diff --git a/hardware_interface/include/hardware_interface/resource_manager.hpp b/hardware_interface/include/hardware_interface/resource_manager.hpp index 4c9f1d4480..4f4eac3ad4 100644 --- a/hardware_interface/include/hardware_interface/resource_manager.hpp +++ b/hardware_interface/include/hardware_interface/resource_manager.hpp @@ -33,7 +33,7 @@ class SensorInterface; class SystemInterface; class ResourceStorage; -class ResourceManager +class HARDWARE_INTERFACE_PUBLIC ResourceManager { public: /// Default constructor for the Resource Manager.