Skip to content

Commit f5d5426

Browse files
jefferyyjhsuskyegalaxy
authored andcommitted
move ipc lock to appropriate position in client.hpp
(cherry picked from commit 9de603e)
1 parent 3e7d6a4 commit f5d5426

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

rclcpp/include/rclcpp/client.hpp

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -893,24 +893,26 @@ class Client : public ClientBase
893893
int64_t
894894
async_send_request_impl(SharedRequest request, CallbackInfoVariant value)
895895
{
896-
std::lock_guard<std::recursive_mutex> ipc_lock(ipc_mutex_);
897-
if (use_intra_process_) {
898-
auto ipm = weak_ipm_.lock();
899-
if (!ipm) {
900-
throw std::runtime_error(
901-
"intra process send called after destruction of intra process manager");
902-
}
903-
bool intra_process_server_available = ipm->service_is_available(intra_process_client_id_);
904-
905-
// Check if there's an intra-process server available matching this client.
906-
// If there's not, we fall back into inter-process communication, since
907-
// the server might be available in another process or was configured to not use IPC.
908-
if (intra_process_server_available) {
909-
// Send intra-process request
910-
ipm->send_intra_process_client_request<ServiceT>(
911-
intra_process_client_id_,
912-
std::make_pair(std::move(request), std::move(value)));
913-
return ipc_sequence_number_++;
896+
{
897+
std::lock_guard<std::recursive_mutex> lock(ipc_mutex_);
898+
if (use_intra_process_) {
899+
auto ipm = weak_ipm_.lock();
900+
if (!ipm) {
901+
throw std::runtime_error(
902+
"intra process send called after destruction of intra process manager");
903+
}
904+
bool intra_process_server_available = ipm->service_is_available(intra_process_client_id_);
905+
906+
// Check if there's an intra-process server available matching this client.
907+
// If there's not, we fall back into inter-process communication, since
908+
// the server might be available in another process or was configured to not use IPC.
909+
if (intra_process_server_available) {
910+
// Send intra-process request
911+
ipm->send_intra_process_client_request<ServiceT>(
912+
intra_process_client_id_,
913+
std::make_pair(std::move(request), std::move(value)));
914+
return ipc_sequence_number_++;
915+
}
914916
}
915917
}
916918

0 commit comments

Comments
 (0)