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 
26 #include "rclcpp/executor.hpp"
27 #include "rclcpp/macros.hpp"
30 
31 namespace rclcpp
32 {
33 namespace executors
34 {
35 
37 {
38 public:
40 
41 
42 
58  size_t number_of_threads = 0,
59  bool yield_before_execute = false,
61 
63  virtual ~MultiThreadedExecutor();
64 
70  void
71  spin() override;
72 
74  size_t
76 
77 protected:
79  void
80  run(size_t this_thread_number);
81 
82 private:
84 
85  detail::MutexTwoPriorities wait_mutex_;
86  size_t number_of_threads_;
87  bool yield_before_execute_;
88  std::chrono::nanoseconds next_exec_timeout_;
89 
90  std::set<TimerBase::SharedPtr> scheduled_timers_;
91 };
92 
93 } // namespace executors
94 } // namespace rclcpp
95 
96 #endif // RCLCPP__EXECUTORS__MULTI_THREADED_EXECUTOR_HPP_
mutex_two_priorities.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:65
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
rclcpp::detail::MutexTwoPriorities
Definition: mutex_two_priorities.hpp:30
visibility_control.hpp
rclcpp::executors::MultiThreadedExecutor
Definition: multi_threaded_executor.hpp:36
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