Compare commits

..

6 Commits

Author SHA1 Message Date
Pedro Pena
a4fe5a5c8c changed type
Signed-off-by: Pedro Pena <peter.a.pena@gmail.com>
2020-07-06 17:05:37 -04:00
Pedro Pena
425a794eb1 fixing warnings
Signed-off-by: Pedro Pena <peter.a.pena@gmail.com>
2020-07-06 17:05:37 -04:00
Pedro Pena
c0f7eb3c45 fixed conversion
Signed-off-by: Pedro Pena <peter.a.pena@gmail.com>
2020-07-06 17:05:37 -04:00
Pedro Pena
39c7ca3b69 uncrustify fixes
Signed-off-by: Pedro Pena <peter.a.pena@gmail.com>
2020-07-06 17:05:37 -04:00
Pedro Pena
44efcf7744 fixed test results (uncrustify)
Signed-off-by: Pedro Pena <peter.a.pena@gmail.com>
2020-07-06 17:05:37 -04:00
Pedro Pena
7b1335dd1d scheduled timer mutex
Signed-off-by: Pedro Pena <peter.a.pena@gmail.com>
2020-07-06 17:05:37 -04:00
12 changed files with 143 additions and 55 deletions

View File

@@ -2,26 +2,6 @@
Changelog for package rclcpp
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4.0.0 (2020-07-09)
------------------
* Fix rclcpp::NodeOptions::operator= (`#1211 <https://github.com/ros2/rclcpp/issues/1211>`_)
* Link against thread library where necessary (`#1210 <https://github.com/ros2/rclcpp/issues/1210>`_)
* Unit tests for node interfaces (`#1202 <https://github.com/ros2/rclcpp/issues/1202>`_)
* Remove usage of domain id in node options (`#1205 <https://github.com/ros2/rclcpp/issues/1205>`_)
* Remove deprecated set_on_parameters_set_callback function (`#1199 <https://github.com/ros2/rclcpp/issues/1199>`_)
* Fix conversion of negative durations to messages (`#1188 <https://github.com/ros2/rclcpp/issues/1188>`_)
* Fix implementation of NodeOptions::use_global_arguments() (`#1176 <https://github.com/ros2/rclcpp/issues/1176>`_)
* Bump to QD to level 3 and fixed links (`#1158 <https://github.com/ros2/rclcpp/issues/1158>`_)
* Fix pub/sub count API tests (`#1203 <https://github.com/ros2/rclcpp/issues/1203>`_)
* Update tracetools' QL to 2 in rclcpp's QD (`#1187 <https://github.com/ros2/rclcpp/issues/1187>`_)
* Fix exception message on rcl_clock_init (`#1182 <https://github.com/ros2/rclcpp/issues/1182>`_)
* Throw exception if rcl_timer_init fails (`#1179 <https://github.com/ros2/rclcpp/issues/1179>`_)
* Unit tests for some header-only functions/classes (`#1181 <https://github.com/ros2/rclcpp/issues/1181>`_)
* Callback should be perfectly-forwarded (`#1183 <https://github.com/ros2/rclcpp/issues/1183>`_)
* Add unit tests for logging functionality (`#1184 <https://github.com/ros2/rclcpp/issues/1184>`_)
* Add create_publisher include to create_subscription (`#1180 <https://github.com/ros2/rclcpp/issues/1180>`_)
* Contributors: Alejandro Hernández Cordero, Christophe Bedard, Claire Wang, Dirk Thomas, Ivan Santiago Paunovic, Johannes Meyer, Michel Hidalgo, Stephen Brawner, tomoya
3.0.0 (2020-06-18)
------------------
* Check period duration in create_wall_timer (`#1178 <https://github.com/ros2/rclcpp/issues/1178>`_)

View File

@@ -82,6 +82,7 @@ private:
RCLCPP_DISABLE_COPY(MultiThreadedExecutor)
std::mutex wait_mutex_;
std::mutex scheduled_timers_mutex_;
size_t number_of_threads_;
bool yield_before_execute_;
std::chrono::nanoseconds next_exec_timeout_;

View File

@@ -2,7 +2,7 @@
<?xml-model href="http://download.ros.org/schema/package_format2.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="2">
<name>rclcpp</name>
<version>4.0.0</version>
<version>3.0.0</version>
<description>The ROS client library in C++.</description>
<maintainer email="dthomas@osrfoundation.org">Dirk Thomas</maintainer>
<license>Apache License 2.0</license>

View File

@@ -83,19 +83,22 @@ MultiThreadedExecutor::run(size_t)
if (!get_next_executable(any_exec, next_exec_timeout_)) {
continue;
}
if (any_exec.timer) {
// Guard against multiple threads getting the same timer.
if (scheduled_timers_.count(any_exec.timer) != 0) {
// Make sure that any_exec's callback group is reset before
// the lock is released.
if (any_exec.callback_group) {
any_exec.callback_group->can_be_taken_from().store(true);
}
continue;
}
scheduled_timers_.insert(any_exec.timer);
}
}
if (any_exec.timer) {
std::lock_guard<std::mutex> wait_lock(scheduled_timers_mutex_);
// Guard against multiple threads getting the same timer.
if (scheduled_timers_.count(any_exec.timer) != 0) {
// Make sure that any_exec's callback group is reset before
// the lock is released.
if (any_exec.callback_group) {
any_exec.callback_group->can_be_taken_from().store(true);
}
continue;
}
scheduled_timers_.insert(any_exec.timer);
}
if (yield_before_execute_) {
std::this_thread::yield();
}
@@ -103,7 +106,7 @@ MultiThreadedExecutor::run(size_t)
execute_any_executable(any_exec);
if (any_exec.timer) {
std::lock_guard<std::mutex> wait_lock(wait_mutex_);
std::lock_guard<std::mutex> wait_lock(scheduled_timers_mutex_);
auto it = scheduled_timers_.find(any_exec.timer);
if (it != scheduled_timers_.end()) {
scheduled_timers_.erase(it);

View File

@@ -464,6 +464,12 @@ if(TARGET test_guard_condition)
target_link_libraries(test_guard_condition ${PROJECT_NAME})
endif()
ament_add_gtest(test_timer_count rclcpp/test_timer_call_count.cpp
APPEND_LIBRARY_DIRS "${append_library_dirs}")
if(TARGET test_timer_count)
target_link_libraries(test_timer_count ${PROJECT_NAME})
endif()
ament_add_gtest(test_wait_set rclcpp/test_wait_set.cpp
APPEND_LIBRARY_DIRS "${append_library_dirs}")
if(TARGET test_wait_set)

View File

@@ -0,0 +1,116 @@
// Copyright 2020 Open Source Robotics Foundation, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <gtest/gtest.h>
#include <chrono>
#include <string>
#include <memory>
#include "rclcpp/rclcpp.hpp"
#include "rclcpp/exceptions.hpp"
#include "rclcpp/node.hpp"
#include "rclcpp/executors.hpp"
#include "rclcpp/executor.hpp"
using namespace std::chrono_literals;
class TestTimerCount : public ::testing::Test
{
protected:
static void SetUpTestCase()
{
rclcpp::init(0, nullptr);
}
};
constexpr int EXECUTION_COUNT = 5;
constexpr rcl_duration_value_t TIME_ELAPSED = 12;
/*
Test timer wait mutex with multithreaded executor.
After 5 call
*/
TEST_F(TestTimerCount, timer_call_count_multi_threaded) {
rclcpp::executors::MultiThreadedExecutor executor;
std::shared_ptr<rclcpp::Node> node =
std::make_shared<rclcpp::Node>("timer_call_count_multi_threaded");
auto cbg = node->create_callback_group(rclcpp::CallbackGroupType::Reentrant);
rclcpp::Clock system_clock(RCL_STEADY_TIME);
std::mutex last_mutex;
rclcpp::Time initial = system_clock.now();
std::atomic_int timer_count {0};
auto timer_callback = [&timer_count, &executor, &system_clock, &last_mutex, &initial]() {
rclcpp::Time now = system_clock.now();
timer_count++;
{
std::lock_guard<std::mutex> lock(last_mutex);
rcl_duration_value_t diff = (now - initial).nanoseconds() / (rcl_duration_value_t)1.0e9;
if (diff > TIME_ELAPSED) {
executor.cancel();
ASSERT_GT(timer_count, EXECUTION_COUNT);
}
}
};
auto timer_ = node->create_wall_timer(
2s, timer_callback, cbg);
executor.add_node(node);
executor.spin();
}
/*
Test timer wait mutex with singlethreaded executor
*/
TEST_F(TestTimerCount, timer_call_count_single_threaded) {
rclcpp::executors::SingleThreadedExecutor executor;
std::shared_ptr<rclcpp::Node> node =
std::make_shared<rclcpp::Node>("timer_call_count_single_threaded");
rclcpp::Clock system_clock(RCL_STEADY_TIME);
std::mutex last_mutex;
rclcpp::Time initial = system_clock.now();
std::atomic_int timer_count {0};
auto timer_callback = [&timer_count, &executor, &system_clock, &last_mutex, &initial]() {
rclcpp::Time now = system_clock.now();
timer_count++;
{
std::lock_guard<std::mutex> lock(last_mutex);
rcl_duration_value_t diff = (now - initial).nanoseconds() / (rcl_duration_value_t)1.0e9;
if (diff > TIME_ELAPSED) {
executor.cancel();
ASSERT_GT(timer_count, EXECUTION_COUNT);
}
}
};
auto timer_ = node->create_wall_timer(
2s, timer_callback);
executor.add_node(node);
executor.spin();
}

View File

@@ -3,11 +3,6 @@ Changelog for package rclcpp_action
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4.0.0 (2020-07-09)
------------------
* Bump to QD to level 3 and fixed links (`#1158 <https://github.com/ros2/rclcpp/issues/1158>`_)
* Contributors: Alejandro Hernández Cordero
3.0.0 (2020-06-18)
------------------
* Add rcl_action_client_options when creating action client. (`#1133 <https://github.com/ros2/rclcpp/issues/1133>`_)

View File

@@ -2,7 +2,7 @@
<?xml-model href="http://download.ros.org/schema/package_format2.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="2">
<name>rclcpp_action</name>
<version>4.0.0</version>
<version>3.0.0</version>
<description>Adds action APIs for C++.</description>
<maintainer email="dthomas@osrfoundation.org">Dirk Thomas</maintainer>
<license>Apache License 2.0</license>

View File

@@ -2,12 +2,6 @@
Changelog for package rclcpp_components
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4.0.0 (2020-07-09)
------------------
* Bump to QD to level 3 and fixed links (`#1158 <https://github.com/ros2/rclcpp/issues/1158>`_)
* Include original exception in ComponentManagerException (`#1157 <https://github.com/ros2/rclcpp/issues/1157>`_)
* Contributors: Alejandro Hernández Cordero, Martijn Buijs, tomoya
3.0.0 (2020-06-18)
------------------

View File

@@ -2,7 +2,7 @@
<?xml-model href="http://download.ros.org/schema/package_format2.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="2">
<name>rclcpp_components</name>
<version>4.0.0</version>
<version>3.0.0</version>
<description>Package containing tools for dynamically loadable components</description>
<maintainer email="michael@openrobotics.org">Michael Carroll</maintainer>
<license>Apache License 2.0</license>

View File

@@ -3,13 +3,6 @@ Changelog for package rclcpp_lifecycle
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4.0.0 (2020-07-09)
------------------
* Remove deprecated set_on_parameters_set_callback function (`#1199 <https://github.com/ros2/rclcpp/issues/1199>`_)
* Bump to QD to level 3 and fixed links (`#1158 <https://github.com/ros2/rclcpp/issues/1158>`_)
* Fix race in test_lifecycle_service_client (`#1204 <https://github.com/ros2/rclcpp/issues/1204>`_)
* Contributors: Alejandro Hernández Cordero, Claire Wang, Dirk Thomas
3.0.0 (2020-06-18)
------------------
* Fix doxygen warnings (`#1163 <https://github.com/ros2/rclcpp/issues/1163>`_)

View File

@@ -2,7 +2,7 @@
<?xml-model href="http://download.ros.org/schema/package_format2.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="2">
<name>rclcpp_lifecycle</name>
<version>4.0.0</version>
<version>3.0.0</version>
<description>Package containing a prototype for lifecycle implementation</description>
<maintainer email="karsten@osrfoundation.org">Karsten Knese</maintainer>
<license>Apache License 2.0</license>