From c9874fabac102861c8e5eaecde89298e7120246d Mon Sep 17 00:00:00 2001 From: Adam Dabrowski Date: Mon, 19 Apr 2021 14:44:56 +0200 Subject: [PATCH] CPU load decrease through spin_some() Signed-off-by: Adam Dabrowski --- .../src/rosbag2_transport/rosbag2_transport.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/rosbag2_transport/src/rosbag2_transport/rosbag2_transport.cpp b/rosbag2_transport/src/rosbag2_transport/rosbag2_transport.cpp index 43080bdd2c..753c9f6400 100644 --- a/rosbag2_transport/src/rosbag2_transport/rosbag2_transport.cpp +++ b/rosbag2_transport/src/rosbag2_transport/rosbag2_transport.cpp @@ -98,7 +98,11 @@ void Recorder::record( exec.add_node(recorder); auto spin_thread = std::thread( [&exec]() { - exec.spin(); + const auto time_step = std::chrono::milliseconds(1); + while (rclcpp::ok()) { + exec.spin_some(); + std::this_thread::sleep_for(time_step); + } }); auto exit = rcpputils::scope_exit( [&exec, &spin_thread]() {