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 <memory>
19 #include <mutex>
20 #include <set>
21 #include <thread>
22 #include <unordered_map>
23 
24 #include "rclcpp/executor.hpp"
25 #include "rclcpp/macros.hpp"
28 
29 namespace rclcpp
30 {
31 namespace executors
32 {
33 
35 {
36 public:
38 
39 
40 
55  size_t number_of_threads = 0,
56  bool yield_before_execute = false);
57 
59  virtual ~MultiThreadedExecutor();
60 
62  void
63  spin();
64 
66  size_t
68 
69 protected:
71  void
72  run(size_t this_thread_number);
73 
74 private:
75  RCLCPP_DISABLE_COPY(MultiThreadedExecutor)
76 
77  std::mutex wait_mutex_;
78  size_t number_of_threads_;
79  bool yield_before_execute_;
80 
81  std::set<TimerBase::SharedPtr> scheduled_timers_;
82 };
83 
84 } // namespace executors
85 } // namespace rclcpp
86 
87 #endif // RCLCPP__EXECUTORS__MULTI_THREADED_EXECUTOR_HPP_
#define RCLCPP_DISABLE_COPY(...)
Definition: macros.hpp:26
MultiThreadedExecutor(const executor::ExecutorArgs &args=executor::ExecutorArgs(), size_t number_of_threads=0, bool yield_before_execute=false)
Constructor for MultiThreadedExecutor.
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_topics_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:95
Definition: multi_threaded_executor.hpp:34
#define RCLCPP_PUBLIC
Definition: visibility_control.hpp:50
Definition: executor.hpp:67