From e9f0328ec80907c88b0a2371b4b489bf68f2a264 Mon Sep 17 00:00:00 2001 From: dhood Date: Sun, 3 Dec 2017 17:11:50 -0800 Subject: [PATCH] Allow client to trigger another service call from its callback (#415) --- rclcpp/include/rclcpp/client.hpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/rclcpp/include/rclcpp/client.hpp b/rclcpp/include/rclcpp/client.hpp index 0816a2d..1637b83 100644 --- a/rclcpp/include/rclcpp/client.hpp +++ b/rclcpp/include/rclcpp/client.hpp @@ -197,7 +197,7 @@ public: std::shared_ptr request_header, std::shared_ptr response) { - std::lock_guard lock(pending_requests_mutex_); + std::unique_lock lock(pending_requests_mutex_); auto typed_response = std::static_pointer_cast(response); int64_t sequence_number = request_header->sequence_number; // TODO(esteve) this should throw instead since it is not expected to happen in the first place @@ -210,6 +210,9 @@ public: auto callback = std::get<1>(tuple); auto future = std::get<2>(tuple); this->pending_requests_.erase(sequence_number); + // Unlock here to allow the service to be called recursively from one of its callbacks. + lock.unlock(); + call_promise->set_value(typed_response); callback(future); }