ROS 2 rclcpp + rcl - lyrical  lyrical
ROS 2 C++ Client Library with ROS Client Library
multi_threaded_executor.hpp
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"
27 #include "rclcpp/visibility_control.hpp"
28 
29 namespace rclcpp
30 {
31 namespace executors
32 {
33 
35 {
36 public:
37  RCLCPP_SMART_PTR_DEFINITIONS(MultiThreadedExecutor)
38 
39 
53  RCLCPP_PUBLIC
54  explicit MultiThreadedExecutor(
56  size_t number_of_threads = 0,
57  bool yield_before_execute = false,
58  std::chrono::nanoseconds timeout = std::chrono::nanoseconds(-1));
59 
60  RCLCPP_PUBLIC
61  virtual ~MultiThreadedExecutor();
62 
67  RCLCPP_PUBLIC
68  void
69  spin() override;
70 
71  RCLCPP_PUBLIC
72  size_t
73  get_number_of_threads();
74 
75 protected:
76  RCLCPP_PUBLIC
77  void
78  run(size_t this_thread_number);
79 
80 private:
81  RCLCPP_DISABLE_COPY(MultiThreadedExecutor)
82 
83  std::mutex wait_mutex_;
84  size_t number_of_threads_;
85  bool yield_before_execute_;
86  std::chrono::nanoseconds next_exec_timeout_;
87 };
88 
89 } // namespace executors
90 } // namespace rclcpp
91 
92 #endif // RCLCPP__EXECUTORS__MULTI_THREADED_EXECUTOR_HPP_
Coordinate the order and timing of available communication tasks.
Definition: executor.hpp:65
RCLCPP_PUBLIC 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.
Versions of rosidl_typesupport_cpp::get_message_type_support_handle that handle adapted types.
Options to be passed to the executor constructor.