Skip to content

Commit

Permalink
Apply comment: add spin_once_impl private method
Browse files Browse the repository at this point in the history
Signed-off-by: Donghee Ye <donghee.ye@samsung.com>
  • Loading branch information
DongheeYe committed Mar 24, 2020
1 parent 14dadad commit 5b6de09
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
9 changes: 5 additions & 4 deletions rclcpp/include/rclcpp/executor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,8 @@ class Executor
RCLCPP_SCOPE_EXIT(this->spinning.store(false); );
while (rclcpp::ok(this->context_) && spinning.load()) {
// Do one item of work.
AnyExecutable any_exec;
if (get_next_executable(any_exec, timeout_left)) {
execute_any_executable(any_exec);
}
spin_once_impl(timeout_left);

// Check if the future is set, return SUCCESS if it is.
status = future.wait_for(std::chrono::seconds(0));
if (status == std::future_status::ready) {
Expand Down Expand Up @@ -368,6 +366,9 @@ class Executor
private:
RCLCPP_DISABLE_COPY(Executor)

void
spin_once_impl(std::chrono::nanoseconds timeout);

std::list<rclcpp::node_interfaces::NodeBaseInterface::WeakPtr> weak_nodes_;
std::list<const rcl_guard_condition_t *> guard_conditions_;
};
Expand Down
13 changes: 9 additions & 4 deletions rclcpp/src/rclcpp/executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,17 +246,22 @@ Executor::spin_some(std::chrono::nanoseconds max_duration)
}
}

void
Executor::spin_once_impl(std::chrono::nanoseconds timeout) {
AnyExecutable any_exec;
if (get_next_executable(any_exec, timeout)) {
execute_any_executable(any_exec);
}
}

void
Executor::spin_once(std::chrono::nanoseconds timeout)
{
if (spinning.exchange(true)) {
throw std::runtime_error("spin_once() called while already spinning");
}
RCLCPP_SCOPE_EXIT(this->spinning.store(false); );
AnyExecutable any_exec;
if (get_next_executable(any_exec, timeout)) {
execute_any_executable(any_exec);
}
spin_once_impl(timeout);
}

void
Expand Down

0 comments on commit 5b6de09

Please sign in to comment.