From ddb3e8fe8bb233fcdfb02165b9237cf8fb8ccaf1 Mon Sep 17 00:00:00 2001 From: Martin Mayer Date: Tue, 3 Jan 2023 20:10:14 +0100 Subject: [PATCH] updated to PIMutex Signed-off-by: Martin Mayer --- rclcpp/include/rclcpp/callback_group.hpp | 7 +++---- rclcpp/include/rclcpp/client.hpp | 7 ++++--- rclcpp/include/rclcpp/clock.hpp | 4 ++-- rclcpp/include/rclcpp/context.hpp | 8 ++++---- rclcpp/include/rclcpp/executor.hpp | 4 ++-- .../rclcpp/executors/multi_threaded_executor.hpp | 5 +++-- .../executors/static_executor_entities_collector.hpp | 4 +++- .../buffers/ring_buffer_implementation.hpp | 5 +++-- rclcpp/include/rclcpp/graph_listener.hpp | 8 ++++---- rclcpp/include/rclcpp/init_options.hpp | 4 ++-- rclcpp/include/rclcpp/node_interfaces/node_base.hpp | 7 ++++--- rclcpp/include/rclcpp/node_interfaces/node_graph.hpp | 6 ++++-- .../subscription_topic_statistics.hpp | 4 +++- .../detail/write_preferring_read_write_lock.hpp | 5 +++-- rclcpp/src/rclcpp/clock.cpp | 12 ++++++------ rclcpp/src/rclcpp/context.cpp | 5 +++-- rclcpp/src/rclcpp/signal_handler.hpp | 5 +++-- rclcpp/src/rclcpp/time_source.cpp | 6 ++++-- rclcpp_action/include/rclcpp_action/client.hpp | 4 ++-- .../include/rclcpp_action/client_goal_handle.hpp | 5 +++-- rclcpp_action/include/rclcpp_action/server.hpp | 4 ++-- .../include/rclcpp_action/server_goal_handle.hpp | 5 +++-- rclcpp_action/src/client.cpp | 9 ++++++--- 23 files changed, 76 insertions(+), 57 deletions(-) diff --git a/rclcpp/include/rclcpp/callback_group.hpp b/rclcpp/include/rclcpp/callback_group.hpp index 7d03edf343..078962f5b0 100644 --- a/rclcpp/include/rclcpp/callback_group.hpp +++ b/rclcpp/include/rclcpp/callback_group.hpp @@ -16,9 +16,7 @@ #define RCLCPP__CALLBACK_GROUP_HPP_ #include -#include -#include -#include +#include #include #include "rclcpp/client.hpp" @@ -30,6 +28,7 @@ #include "rclcpp/timer.hpp" #include "rclcpp/visibility_control.hpp" #include "rclcpp/waitable.hpp" +#include "rcpputils/mutex.hpp" namespace rclcpp { @@ -221,7 +220,7 @@ class CallbackGroup CallbackGroupType type_; // Mutex to protect the subsequent vectors of pointers. - mutable std::mutex mutex_; + mutable rcpputils::PIMutex mutex_; std::atomic_bool associated_with_executor_; std::vector subscription_ptrs_; std::vector timer_ptrs_; diff --git a/rclcpp/include/rclcpp/client.hpp b/rclcpp/include/rclcpp/client.hpp index c3a2210a71..dffa5e7347 100644 --- a/rclcpp/include/rclcpp/client.hpp +++ b/rclcpp/include/rclcpp/client.hpp @@ -19,7 +19,6 @@ #include #include #include -#include #include // NOLINT, cpplint doesn't think this is a cpp std header #include #include @@ -45,6 +44,8 @@ #include "rclcpp/utilities.hpp" #include "rclcpp/visibility_control.hpp" +#include "rcpputils/mutex.hpp" + #include "rmw/error_handling.h" #include "rmw/impl/cpp/demangle.hpp" #include "rmw/rmw.h" @@ -364,7 +365,7 @@ class ClientBase std::atomic in_use_by_wait_set_{false}; - std::recursive_mutex callback_mutex_; + rcpputils::RecursivePIMutex callback_mutex_; std::function on_new_response_callback_{nullptr}; }; @@ -830,7 +831,7 @@ class Client : public ClientBase std::chrono::time_point, CallbackInfoVariant>> pending_requests_; - std::mutex pending_requests_mutex_; + rcpputils::PIMutex pending_requests_mutex_; }; } // namespace rclcpp diff --git a/rclcpp/include/rclcpp/clock.hpp b/rclcpp/include/rclcpp/clock.hpp index 702b224d53..1995a20f68 100644 --- a/rclcpp/include/rclcpp/clock.hpp +++ b/rclcpp/include/rclcpp/clock.hpp @@ -17,7 +17,6 @@ #include #include -#include #include "rclcpp/contexts/default_context.hpp" #include "rclcpp/macros.hpp" @@ -27,6 +26,7 @@ #include "rcl/time.h" #include "rcutils/time.h" #include "rcutils/types/rcutils_ret.h" +#include "rcpputils/mutex.hpp" namespace rclcpp { @@ -204,7 +204,7 @@ class Clock /// Get the clock's mutex RCLCPP_PUBLIC - std::mutex & + rcpputils::PIMutex & get_clock_mutex() noexcept; // Add a callback to invoke if the jump threshold is exceeded. diff --git a/rclcpp/include/rclcpp/context.hpp b/rclcpp/include/rclcpp/context.hpp index 3add3f6d46..2f84b38596 100644 --- a/rclcpp/include/rclcpp/context.hpp +++ b/rclcpp/include/rclcpp/context.hpp @@ -18,7 +18,6 @@ #include #include #include -#include #include #include #include @@ -33,6 +32,7 @@ #include "rclcpp/init_options.hpp" #include "rclcpp/macros.hpp" #include "rclcpp/visibility_control.hpp" +#include "rcpputils/mutex.hpp" namespace rclcpp { @@ -377,15 +377,15 @@ class Context : public std::enable_shared_from_this std::recursive_mutex sub_contexts_mutex_; std::unordered_set> on_shutdown_callbacks_; - mutable std::mutex on_shutdown_callbacks_mutex_; + mutable rcpputils::PIMutex on_shutdown_callbacks_mutex_; std::unordered_set> pre_shutdown_callbacks_; - mutable std::mutex pre_shutdown_callbacks_mutex_; + mutable rcpputils::PIMutex pre_shutdown_callbacks_mutex_; /// Condition variable for timed sleep (see sleep_for). std::condition_variable interrupt_condition_variable_; /// Mutex for protecting the global condition variable. - std::mutex interrupt_mutex_; + rcpputils::PIMutex interrupt_mutex_; /// Keep shared ownership of global vector of weak contexts std::shared_ptr weak_contexts_; diff --git a/rclcpp/include/rclcpp/executor.hpp b/rclcpp/include/rclcpp/executor.hpp index 65d0a930cb..df1581fcd0 100644 --- a/rclcpp/include/rclcpp/executor.hpp +++ b/rclcpp/include/rclcpp/executor.hpp @@ -23,13 +23,13 @@ #include #include #include -#include #include #include #include "rcl/guard_condition.h" #include "rcl/wait.h" #include "rcpputils/scope_exit.hpp" +#include "rcpputils/mutex.hpp" #include "rclcpp/context.hpp" #include "rclcpp/contexts/default_context.hpp" @@ -545,7 +545,7 @@ class Executor rcl_wait_set_t wait_set_ = rcl_get_zero_initialized_wait_set(); // Mutex to protect the subsequent memory_strategy_. - mutable std::mutex mutex_; + mutable rcpputils::PIMutex mutex_; /// The memory strategy: an interface for handling user-defined memory allocation strategies. memory_strategy::MemoryStrategy::SharedPtr diff --git a/rclcpp/include/rclcpp/executors/multi_threaded_executor.hpp b/rclcpp/include/rclcpp/executors/multi_threaded_executor.hpp index 119013ebfb..09ab2803a4 100644 --- a/rclcpp/include/rclcpp/executors/multi_threaded_executor.hpp +++ b/rclcpp/include/rclcpp/executors/multi_threaded_executor.hpp @@ -17,7 +17,6 @@ #include #include -#include #include #include #include @@ -27,6 +26,8 @@ #include "rclcpp/memory_strategies.hpp" #include "rclcpp/visibility_control.hpp" +#include "rcpputils/mutex.hpp" + namespace rclcpp { namespace executors @@ -81,7 +82,7 @@ class MultiThreadedExecutor : public rclcpp::Executor private: RCLCPP_DISABLE_COPY(MultiThreadedExecutor) - std::mutex wait_mutex_; + rcpputils::PIMutex wait_mutex_; size_t number_of_threads_; bool yield_before_execute_; std::chrono::nanoseconds next_exec_timeout_; diff --git a/rclcpp/include/rclcpp/executors/static_executor_entities_collector.hpp b/rclcpp/include/rclcpp/executors/static_executor_entities_collector.hpp index f9fd2ff672..2e0a437c7d 100644 --- a/rclcpp/include/rclcpp/executors/static_executor_entities_collector.hpp +++ b/rclcpp/include/rclcpp/executors/static_executor_entities_collector.hpp @@ -30,6 +30,8 @@ #include "rclcpp/visibility_control.hpp" #include "rclcpp/waitable.hpp" +#include "rcpputils/mutex.hpp" + namespace rclcpp { namespace executors @@ -338,7 +340,7 @@ class StaticExecutorEntitiesCollector final std::list weak_nodes_; // Mutex to protect vector of new nodes. - std::mutex new_nodes_mutex_; + rcpputils::PIMutex new_nodes_mutex_; std::vector new_nodes_; /// Wait set for managing entities that the rmw layer waits on. diff --git a/rclcpp/include/rclcpp/experimental/buffers/ring_buffer_implementation.hpp b/rclcpp/include/rclcpp/experimental/buffers/ring_buffer_implementation.hpp index 245d417d86..51b023d2b4 100644 --- a/rclcpp/include/rclcpp/experimental/buffers/ring_buffer_implementation.hpp +++ b/rclcpp/include/rclcpp/experimental/buffers/ring_buffer_implementation.hpp @@ -15,7 +15,6 @@ #ifndef RCLCPP__EXPERIMENTAL__BUFFERS__RING_BUFFER_IMPLEMENTATION_HPP_ #define RCLCPP__EXPERIMENTAL__BUFFERS__RING_BUFFER_IMPLEMENTATION_HPP_ -#include #include #include #include @@ -26,6 +25,8 @@ #include "rclcpp/macros.hpp" #include "rclcpp/visibility_control.hpp" +#include "rcpputils/mutex.hpp" + namespace rclcpp { namespace experimental @@ -181,7 +182,7 @@ class RingBufferImplementation : public BufferImplementationBase size_t read_index_; size_t size_; - mutable std::mutex mutex_; + mutable rcpputils::PIMutex mutex_; }; } // namespace buffers diff --git a/rclcpp/include/rclcpp/graph_listener.hpp b/rclcpp/include/rclcpp/graph_listener.hpp index 7d7f787fe8..926e76b264 100644 --- a/rclcpp/include/rclcpp/graph_listener.hpp +++ b/rclcpp/include/rclcpp/graph_listener.hpp @@ -17,7 +17,6 @@ #include #include -#include #include #include @@ -28,6 +27,7 @@ #include "rclcpp/macros.hpp" #include "rclcpp/node_interfaces/node_graph_interface.hpp" #include "rclcpp/visibility_control.hpp" +#include "rcpputils/mutex.hpp" namespace rclcpp { @@ -187,10 +187,10 @@ class GraphListener : public std::enable_shared_from_this std::thread listener_thread_; bool is_started_; std::atomic_bool is_shutdown_; - mutable std::mutex shutdown_mutex_; + mutable rcpputils::PIMutex shutdown_mutex_; - mutable std::mutex node_graph_interfaces_barrier_mutex_; - mutable std::mutex node_graph_interfaces_mutex_; + mutable rcpputils::PIMutex node_graph_interfaces_barrier_mutex_; + mutable rcpputils::PIMutex node_graph_interfaces_mutex_; std::vector node_graph_interfaces_; rclcpp::GuardCondition interrupt_guard_condition_; diff --git a/rclcpp/include/rclcpp/init_options.hpp b/rclcpp/include/rclcpp/init_options.hpp index ab1346db32..d3b615702e 100644 --- a/rclcpp/include/rclcpp/init_options.hpp +++ b/rclcpp/include/rclcpp/init_options.hpp @@ -16,10 +16,10 @@ #define RCLCPP__INIT_OPTIONS_HPP_ #include -#include #include "rcl/init_options.h" #include "rclcpp/visibility_control.hpp" +#include "rcpputils/mutex.hpp" namespace rclcpp { @@ -104,7 +104,7 @@ class InitOptions void finalize_init_options_impl(); - mutable std::mutex init_options_mutex_; + mutable rcpputils::PIMutex init_options_mutex_; std::unique_ptr init_options_; bool initialize_logging_{true}; }; diff --git a/rclcpp/include/rclcpp/node_interfaces/node_base.hpp b/rclcpp/include/rclcpp/node_interfaces/node_base.hpp index a6c84e4aa0..5e08dcc26c 100644 --- a/rclcpp/include/rclcpp/node_interfaces/node_base.hpp +++ b/rclcpp/include/rclcpp/node_interfaces/node_base.hpp @@ -17,7 +17,6 @@ #include #include -#include #include #include @@ -28,6 +27,8 @@ #include "rclcpp/node_interfaces/node_base_interface.hpp" #include "rclcpp/visibility_control.hpp" +#include "rcpputils/mutex.hpp" + namespace rclcpp { namespace node_interfaces @@ -146,13 +147,13 @@ class NodeBase : public NodeBaseInterface, public std::enable_shared_from_this node_handle_; rclcpp::CallbackGroup::SharedPtr default_callback_group_; - std::mutex callback_groups_mutex_; + rcpputils::PIMutex callback_groups_mutex_; std::vector callback_groups_; std::atomic_bool associated_with_executor_; /// Guard condition for notifying the Executor of changes to this node. - mutable std::recursive_mutex notify_guard_condition_mutex_; + mutable rcpputils::RecursivePIMutex notify_guard_condition_mutex_; rclcpp::GuardCondition notify_guard_condition_; bool notify_guard_condition_is_valid_; }; diff --git a/rclcpp/include/rclcpp/node_interfaces/node_graph.hpp b/rclcpp/include/rclcpp/node_interfaces/node_graph.hpp index d167515784..9a63a945c4 100644 --- a/rclcpp/include/rclcpp/node_interfaces/node_graph.hpp +++ b/rclcpp/include/rclcpp/node_interfaces/node_graph.hpp @@ -20,7 +20,6 @@ #include #include #include -#include #include #include #include @@ -33,6 +32,9 @@ #include "rclcpp/node_interfaces/node_base_interface.hpp" #include "rclcpp/node_interfaces/node_graph_interface.hpp" #include "rclcpp/visibility_control.hpp" + +#include "rcpputils/mutex.hpp" + #include "rmw/topic_endpoint_info_array.h" namespace rclcpp @@ -163,7 +165,7 @@ class NodeGraph : public NodeGraphInterface std::atomic_bool should_add_to_graph_listener_; /// Mutex to guard the graph event related data structures. - mutable std::mutex graph_mutex_; + mutable rcpputils::PIMutex graph_mutex_; /// For notifying waiting threads (wait_for_graph_change()) on changes (notify_graph_change()). std::condition_variable graph_cv_; /// Weak references to graph events out on loan. diff --git a/rclcpp/include/rclcpp/topic_statistics/subscription_topic_statistics.hpp b/rclcpp/include/rclcpp/topic_statistics/subscription_topic_statistics.hpp index 4b9221406f..9b85d7cf2c 100644 --- a/rclcpp/include/rclcpp/topic_statistics/subscription_topic_statistics.hpp +++ b/rclcpp/include/rclcpp/topic_statistics/subscription_topic_statistics.hpp @@ -33,6 +33,8 @@ #include "statistics_msgs/msg/metrics_message.hpp" +#include "rcpputils/mutex.hpp" + namespace rclcpp { namespace topic_statistics @@ -227,7 +229,7 @@ class SubscriptionTopicStatistics } /// Mutex to protect the subsequence vectors - mutable std::mutex mutex_; + mutable rcpputils::PIMutex mutex_; /// Collection of statistics collectors std::vector> subscriber_statistics_collectors_{}; /// Node name used to generate topic statistics messages to be published diff --git a/rclcpp/include/rclcpp/wait_set_policies/detail/write_preferring_read_write_lock.hpp b/rclcpp/include/rclcpp/wait_set_policies/detail/write_preferring_read_write_lock.hpp index 933bbf6895..6d5db83ee2 100644 --- a/rclcpp/include/rclcpp/wait_set_policies/detail/write_preferring_read_write_lock.hpp +++ b/rclcpp/include/rclcpp/wait_set_policies/detail/write_preferring_read_write_lock.hpp @@ -17,10 +17,11 @@ #include #include -#include #include "rclcpp/visibility_control.hpp" +#include "rcpputils/mutex.hpp" + namespace rclcpp { namespace wait_set_policies @@ -229,7 +230,7 @@ class WritePreferringReadWriteLock final bool reader_active_ = false; std::size_t number_of_writers_waiting_ = 0; bool writer_active_ = false; - std::mutex mutex_; + rcpputils::PIMutex mutex_; std::condition_variable condition_variable_; ReadMutex read_mutex_; WriteMutex write_mutex_; diff --git a/rclcpp/src/rclcpp/clock.cpp b/rclcpp/src/rclcpp/clock.cpp index f46649a77d..95f9f5311f 100644 --- a/rclcpp/src/rclcpp/clock.cpp +++ b/rclcpp/src/rclcpp/clock.cpp @@ -49,7 +49,7 @@ class Clock::Impl rcl_clock_t rcl_clock_; rcl_allocator_t allocator_; - std::mutex clock_mutex_; + rcpputils::PIMutex clock_mutex_; }; JumpHandler::JumpHandler( @@ -113,7 +113,7 @@ Clock::sleep_until(Time until, Context::SharedPtr context) chrono_entry + std::chrono::nanoseconds(delta_t.nanoseconds()); // loop over spurious wakeups but notice shutdown - std::unique_lock lock(impl_->clock_mutex_); + std::unique_lock lock(impl_->clock_mutex_); while (now() < until && context->is_valid()) { cv.wait_until(lock, chrono_until); } @@ -124,7 +124,7 @@ Clock::sleep_until(Time until, Context::SharedPtr context) std::chrono::nanoseconds(until.nanoseconds()))); // loop over spurious wakeups but notice shutdown - std::unique_lock lock(impl_->clock_mutex_); + std::unique_lock lock(impl_->clock_mutex_); while (now() < until && context->is_valid()) { cv.wait_until(lock, system_time); } @@ -154,7 +154,7 @@ Clock::sleep_until(Time until, Context::SharedPtr context) std::chrono::nanoseconds(until.nanoseconds()))); // loop over spurious wakeups but notice shutdown or time source change - std::unique_lock lock(impl_->clock_mutex_); + std::unique_lock lock(impl_->clock_mutex_); while (now() < until && context->is_valid() && !time_source_changed) { cv.wait_until(lock, system_time); } @@ -162,7 +162,7 @@ Clock::sleep_until(Time until, Context::SharedPtr context) // RCL_ROS_TIME with ros_time_is_active. // Just wait without "until" because installed // jump callbacks wake the cv on every new sample. - std::unique_lock lock(impl_->clock_mutex_); + std::unique_lock lock(impl_->clock_mutex_); while (now() < until && context->is_valid() && !time_source_changed) { cv.wait(lock); } @@ -276,7 +276,7 @@ Clock::get_clock_type() const noexcept return impl_->rcl_clock_.type; } -std::mutex & +rcpputils::PIMutex & Clock::get_clock_mutex() noexcept { return impl_->clock_mutex_; diff --git a/rclcpp/src/rclcpp/context.cpp b/rclcpp/src/rclcpp/context.cpp index 1599172e2e..153cdc2140 100644 --- a/rclcpp/src/rclcpp/context.cpp +++ b/rclcpp/src/rclcpp/context.cpp @@ -15,7 +15,6 @@ #include "rclcpp/context.hpp" #include -#include #include #include #include @@ -32,6 +31,8 @@ #include "rcutils/error_handling.h" #include "rcutils/macros.h" +#include "rcpputils/mutex.hpp" + #include "./logging_mutex.hpp" using rclcpp::Context; @@ -91,7 +92,7 @@ class WeakContextsWrapper private: std::vector> weak_contexts_; - std::mutex mutex_; + rcpputils::PIMutex mutex_; }; } // namespace rclcpp diff --git a/rclcpp/src/rclcpp/signal_handler.hpp b/rclcpp/src/rclcpp/signal_handler.hpp index 0d3c399ccb..cd33e03985 100644 --- a/rclcpp/src/rclcpp/signal_handler.hpp +++ b/rclcpp/src/rclcpp/signal_handler.hpp @@ -17,12 +17,13 @@ #include #include -#include #include #include "rclcpp/logging.hpp" #include "rclcpp/utilities.hpp" +#include "rcpputils/mutex.hpp" + // includes for semaphore notification code #if defined(_WIN32) #include @@ -193,7 +194,7 @@ class SignalHandler final std::thread signal_handler_thread_; // A mutex used to synchronize the install() and uninstall() methods. - std::mutex install_mutex_; + rcpputils::PIMutex install_mutex_; // Whether or not the signal handler has been installed. std::atomic_bool installed_ = false; diff --git a/rclcpp/src/rclcpp/time_source.cpp b/rclcpp/src/rclcpp/time_source.cpp index bf1f9b3daa..fb84826fef 100644 --- a/rclcpp/src/rclcpp/time_source.cpp +++ b/rclcpp/src/rclcpp/time_source.cpp @@ -30,6 +30,8 @@ #include "rclcpp/time.hpp" #include "rclcpp/time_source.hpp" +#include "rcpputils/mutex.hpp" + namespace rclcpp { @@ -191,7 +193,7 @@ class ClocksState final Logger logger_; // A lock to protect iterating the associated_clocks_ field. - std::mutex clock_list_lock_; + rcpputils::PIMutex clock_list_lock_; // A vector to store references to associated clocks. std::vector associated_clocks_; @@ -358,7 +360,7 @@ class TimeSource::NodeState final // The subscription for the clock callback using SubscriptionT = rclcpp::Subscription; std::shared_ptr clock_subscription_{nullptr}; - std::mutex clock_sub_lock_; + rcpputils::PIMutex clock_sub_lock_; rclcpp::CallbackGroup::SharedPtr clock_callback_group_; rclcpp::executors::SingleThreadedExecutor::SharedPtr clock_executor_; std::promise cancel_clock_executor_promise_; diff --git a/rclcpp_action/include/rclcpp_action/client.hpp b/rclcpp_action/include/rclcpp_action/client.hpp index a9bf2a5008..901865f6e0 100644 --- a/rclcpp_action/include/rclcpp_action/client.hpp +++ b/rclcpp_action/include/rclcpp_action/client.hpp @@ -21,7 +21,6 @@ #include #include #include -#include #include #include #include @@ -45,6 +44,7 @@ #include "rclcpp_action/types.hpp" #include "rclcpp_action/visibility_control.hpp" +#include "rcpputils/mutex.hpp" namespace rclcpp_action { @@ -755,7 +755,7 @@ class Client : public ClientBase } std::map goal_handles_; - std::mutex goal_handles_mutex_; + rcpputils::PIMutex goal_handles_mutex_; }; } // namespace rclcpp_action diff --git a/rclcpp_action/include/rclcpp_action/client_goal_handle.hpp b/rclcpp_action/include/rclcpp_action/client_goal_handle.hpp index dd3a40671c..238aaf221d 100644 --- a/rclcpp_action/include/rclcpp_action/client_goal_handle.hpp +++ b/rclcpp_action/include/rclcpp_action/client_goal_handle.hpp @@ -18,7 +18,6 @@ #include #include #include -#include #include "rcl_action/action_client.h" @@ -30,6 +29,8 @@ #include "rclcpp_action/types.hpp" #include "rclcpp_action/visibility_control.hpp" +#include "rcpputils/mutex.hpp" + namespace rclcpp_action { /// The possible statuses that an action goal can finish with. @@ -163,7 +164,7 @@ class ClientGoalHandle ResultCallback result_callback_{nullptr}; int8_t status_{GoalStatus::STATUS_ACCEPTED}; - std::mutex handle_mutex_; + rcpputils::PIMutex handle_mutex_; }; } // namespace rclcpp_action diff --git a/rclcpp_action/include/rclcpp_action/server.hpp b/rclcpp_action/include/rclcpp_action/server.hpp index 892de5743b..9e159f083d 100644 --- a/rclcpp_action/include/rclcpp_action/server.hpp +++ b/rclcpp_action/include/rclcpp_action/server.hpp @@ -17,7 +17,6 @@ #include #include -#include #include #include #include @@ -30,6 +29,7 @@ #include "rclcpp/node_interfaces/node_clock_interface.hpp" #include "rclcpp/node_interfaces/node_logging_interface.hpp" #include "rclcpp/waitable.hpp" +#include "rcpputils/mutex.hpp" #include "rclcpp_action/visibility_control.hpp" #include "rclcpp_action/server_goal_handle.hpp" @@ -564,7 +564,7 @@ class Server : public ServerBase, public std::enable_shared_from_this goal_handles_; - std::mutex goal_handles_mutex_; + rcpputils::PIMutex goal_handles_mutex_; }; } // namespace rclcpp_action #endif // RCLCPP_ACTION__SERVER_HPP_ diff --git a/rclcpp_action/include/rclcpp_action/server_goal_handle.hpp b/rclcpp_action/include/rclcpp_action/server_goal_handle.hpp index ac9dd49492..8f76e4c104 100644 --- a/rclcpp_action/include/rclcpp_action/server_goal_handle.hpp +++ b/rclcpp_action/include/rclcpp_action/server_goal_handle.hpp @@ -17,7 +17,6 @@ #include #include -#include #include "rcl_action/types.h" #include "rcl_action/goal_handle.h" @@ -27,6 +26,8 @@ #include "rclcpp_action/visibility_control.hpp" #include "rclcpp_action/types.hpp" +#include "rcpputils/mutex.hpp" + namespace rclcpp_action { @@ -113,7 +114,7 @@ class ServerGoalHandleBase private: std::shared_ptr rcl_handle_; - mutable std::mutex rcl_handle_mutex_; + mutable rcpputils::PIMutex rcl_handle_mutex_; }; // Forward declare server diff --git a/rclcpp_action/src/client.cpp b/rclcpp_action/src/client.cpp index e687ab3400..81dfa7996a 100644 --- a/rclcpp_action/src/client.cpp +++ b/rclcpp_action/src/client.cpp @@ -22,12 +22,15 @@ #include "rcl_action/action_client.h" #include "rcl_action/wait.h" + #include "rclcpp/node_interfaces/node_base_interface.hpp" #include "rclcpp/node_interfaces/node_logging_interface.hpp" #include "rclcpp_action/client.hpp" #include "rclcpp_action/exceptions.hpp" +#include "rcpputils/mutex.hpp" + namespace rclcpp_action { @@ -110,13 +113,13 @@ class ClientBaseImpl using ResponseCallback = std::function response)>; std::map pending_goal_responses; - std::mutex goal_requests_mutex; + rcpputils::PIMutex goal_requests_mutex; std::map pending_result_responses; - std::mutex result_requests_mutex; + rcpputils::PIMutex result_requests_mutex; std::map pending_cancel_responses; - std::mutex cancel_requests_mutex; + rcpputils::PIMutex cancel_requests_mutex; std::independent_bits_engine< std::default_random_engine, 8, unsigned int> random_bytes_generator;