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 
56  size_t number_of_threads = 0,
57  bool yield_before_execute = false,
59 
61  virtual ~MultiThreadedExecutor();
62 
64  void
65  spin();
66 
68  size_t
70 
71 protected:
73  void
74  run(size_t this_thread_number);
75 
76 private:
77  RCLCPP_DISABLE_COPY(MultiThreadedExecutor)
78 
79  std::mutex wait_mutex_;
80  size_t number_of_threads_;
81  bool yield_before_execute_;
82  std::chrono::nanoseconds next_exec_timeout_;
83 
84  std::set<TimerBase::SharedPtr> scheduled_timers_;
85 };
86 
87 } // namespace executors
88 } // namespace rclcpp
89 
90 #endif // RCLCPP__EXECUTORS__MULTI_THREADED_EXECUTOR_HPP_
MultiThreadedExecutor(const executor::ExecutorArgs &args=executor::ExecutorArgs(), size_t number_of_threads=0, bool yield_before_execute=false, std::chrono::nanoseconds timeout=std::chrono::nanoseconds(-1))
Constructor for MultiThreadedExecutor.
#define RCLCPP_DISABLE_COPY(...)
Definition: macros.hpp:26
void spin()
Do work periodically as it becomes available to us. Blocking call, may block indefinitely.
void run(size_t this_thread_number)
This header provides the get_node_base_interface() template function.
Definition: allocator_common.hpp:24
#define RCLCPP_SMART_PTR_DEFINITIONS(...)
Definition: macros.hpp:36
Coordinate the order and timing of available communication tasks.
Definition: executor.hpp:97
Definition: multi_threaded_executor.hpp:35
#define RCLCPP_PUBLIC
Definition: visibility_control.hpp:50
Definition: executor.hpp:69