Skip to content

Commit

Permalink
Add timer tracking for executor.
Browse files Browse the repository at this point in the history
  • Loading branch information
mjcarroll committed Mar 28, 2018
1 parent cc48c11 commit c94c152
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
3 changes: 2 additions & 1 deletion rclcpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ if(BUILD_TESTING)
ament_target_dependencies(test_utilities
"rcl")
target_link_libraries(test_utilities ${PROJECT_NAME})
endif()

ament_add_gtest(test_multi_threaded_executor test/executors/test_multi_threaded_executor.cpp
APPEND_LIBRARY_DIRS "${append_library_dirs}")
Expand All @@ -337,7 +338,7 @@ if(BUILD_TESTING)
"rcl")
target_link_libraries(test_multi_threaded_executor ${PROJECT_NAME})
endif()
endif()
endif(BUILD_TESTING)

ament_package(
CONFIG_EXTRAS rclcpp-extras.cmake
Expand Down
2 changes: 2 additions & 0 deletions rclcpp/include/rclcpp/executor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <iostream>
#include <list>
#include <memory>
#include <set>
#include <string>
#include <vector>

Expand Down Expand Up @@ -351,6 +352,7 @@ class Executor
RCLCPP_DISABLE_COPY(Executor)

std::vector<rclcpp::node_interfaces::NodeBaseInterface::WeakPtr> weak_nodes_;
std::set<rclcpp::TimerBase::SharedPtr> taken_timers_;
};

} // namespace executor
Expand Down
8 changes: 7 additions & 1 deletion rclcpp/src/rclcpp/executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,10 @@ Executor::execute_any_executable(AnyExecutable::SharedPtr any_exec)
}
if (any_exec->timer) {
execute_timer(any_exec->timer);
auto it = taken_timers_.find(any_exec->timer);
if (it != taken_timers_.end()) {
taken_timers_.erase(it);
}
}
if (any_exec->subscription) {
execute_subscription(any_exec->subscription);
Expand Down Expand Up @@ -522,10 +526,12 @@ Executor::get_next_timer(AnyExecutable::SharedPtr any_exec)
}
for (auto & timer_ref : group->get_timer_ptrs()) {
auto timer = timer_ref.lock();
if (timer && timer->is_ready()) {

if (timer && timer->is_ready() && taken_timers_.count(timer) == 0) {
any_exec->timer = timer;
any_exec->callback_group = group;
node = get_node_by_group(group);
taken_timers_.insert(timer);
return;
}
}
Expand Down

0 comments on commit c94c152

Please sign in to comment.