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 
52  const executor::ExecutorArgs & args = rclcpp::executor::create_default_executor_arguments(),
53  size_t number_of_threads = 0,
54  bool yield_before_execute = false);
55 
57  virtual ~MultiThreadedExecutor();
58 
60  void
61  spin();
62 
64  size_t
66 
67 protected:
69  void
70  run(size_t this_thread_number);
71 
72 private:
74 
75  std::mutex wait_mutex_;
76  size_t number_of_threads_;
77  bool yield_before_execute_;
78 
79  std::mutex scheduled_timers_mutex_;
80  std::set<TimerBase::SharedPtr> scheduled_timers_;
81 };
82 
83 } // namespace executors
84 } // namespace rclcpp
85 
86 #endif // RCLCPP__EXECUTORS__MULTI_THREADED_EXECUTOR_HPP_
Definition: executor.hpp:66
#define RCLCPP_DISABLE_COPY(...)
Definition: macros.hpp:26
Definition: allocator_common.hpp:24
void run(size_t this_thread_number)
#define RCLCPP_SMART_PTR_DEFINITIONS(...)
Definition: macros.hpp:36
Coordinate the order and timing of available communication tasks.
Definition: executor.hpp:90
void spin()
Do work periodically as it becomes available to us. Blocking call, may block indefinitely.
MultiThreadedExecutor(const executor::ExecutorArgs &args=rclcpp::executor::create_default_executor_arguments(), size_t number_of_threads=0, bool yield_before_execute=false)
Constructor for MultiThreadedExecutor.
#define RCLCPP_PUBLIC
Definition: visibility_control.hpp:50
Definition: multi_threaded_executor.hpp:34