rclcpp  master
C++ ROS Client Library API
multi_threaded_executor.hpp
Go to the documentation of this file.
1 // Copyright 2014 Open Source Robotics Foundation, Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef RCLCPP__EXECUTORS__MULTI_THREADED_EXECUTOR_HPP_
16 #define RCLCPP__EXECUTORS__MULTI_THREADED_EXECUTOR_HPP_
17 
18 #include <chrono>
19 #include <memory>
20 #include <mutex>
21 #include <set>
22 #include <thread>
23 #include <unordered_map>
24 
25 #include "rclcpp/executor.hpp"
26 #include "rclcpp/macros.hpp"
29 
30 namespace rclcpp
31 {
32 namespace executors
33 {
34 
36 {
37 public:
39 
40 
41 
57  size_t number_of_threads = 0,
58  bool yield_before_execute = false,
60 
62  virtual ~MultiThreadedExecutor();
63 
69  void
70  spin() override;
71 
73  size_t
75 
76 protected:
78  void
79  run(size_t this_thread_number);
80 
81 private:
83 
84  std::mutex wait_mutex_;
85  size_t number_of_threads_;
86  bool yield_before_execute_;
87  std::chrono::nanoseconds next_exec_timeout_;
88 
89  std::set<TimerBase::SharedPtr> scheduled_timers_;
90 };
91 
92 } // namespace executors
93 } // namespace rclcpp
94 
95 #endif // RCLCPP__EXECUTORS__MULTI_THREADED_EXECUTOR_HPP_
RCLCPP_DISABLE_COPY
#define RCLCPP_DISABLE_COPY(...)
Definition: macros.hpp:26
std::chrono::nanoseconds
rclcpp::Executor
Coordinate the order and timing of available communication tasks.
Definition: executor.hpp:58
rclcpp::executors::MultiThreadedExecutor::run
void run(size_t this_thread_number)
rclcpp
This header provides the get_node_base_interface() template function.
Definition: allocator_common.hpp:24
RCLCPP_PUBLIC
#define RCLCPP_PUBLIC
Definition: visibility_control.hpp:50
rclcpp::executors::MultiThreadedExecutor::~MultiThreadedExecutor
virtual ~MultiThreadedExecutor()
RCLCPP_SMART_PTR_DEFINITIONS
#define RCLCPP_SMART_PTR_DEFINITIONS(...)
Definition: macros.hpp:36
macros.hpp
rclcpp::ExecutorOptions
Options to be passed to the executor constructor.
Definition: executor_options.hpp:28
executor.hpp
visibility_control.hpp
rclcpp::executors::MultiThreadedExecutor
Definition: multi_threaded_executor.hpp:35
std::mutex
rclcpp::executors::MultiThreadedExecutor::MultiThreadedExecutor
MultiThreadedExecutor(const rclcpp::ExecutorOptions &options=rclcpp::ExecutorOptions(), size_t number_of_threads=0, bool yield_before_execute=false, std::chrono::nanoseconds timeout=std::chrono::nanoseconds(-1))
Constructor for MultiThreadedExecutor.
rclcpp::executors::MultiThreadedExecutor::get_number_of_threads
size_t get_number_of_threads()
rclcpp::executors::MultiThreadedExecutor::spin
void spin() override
std::set< TimerBase::SharedPtr >
memory_strategies.hpp