Skip to content

Commit 9de603e

Browse files
jefferyyjhsuapojomovsky
authored andcommitted
move ipc lock to appropriate position in client.hpp
1 parent 378223d commit 9de603e

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
@@ -878,24 +878,26 @@ class Client : public ClientBase
878878
int64_t
879879
async_send_request_impl(SharedRequest request, CallbackInfoVariant value)
880880
{
881-
std::lock_guard<std::recursive_mutex> ipc_lock(ipc_mutex_);
882-
if (use_intra_process_) {
883-
auto ipm = weak_ipm_.lock();
884-
if (!ipm) {
885-
throw std::runtime_error(
886-
"intra process send called after destruction of intra process manager");
887-
}
888-
bool intra_process_server_available = ipm->service_is_available(intra_process_client_id_);
889-
890-
// Check if there's an intra-process server available matching this client.
891-
// If there's not, we fall back into inter-process communication, since
892-
// the server might be available in another process or was configured to not use IPC.
893-
if (intra_process_server_available) {
894-
// Send intra-process request
895-
ipm->send_intra_process_client_request<ServiceT>(
896-
intra_process_client_id_,
897-
std::make_pair(std::move(request), std::move(value)));
898-
return ipc_sequence_number_++;
881+
{
882+
std::lock_guard<std::recursive_mutex> lock(ipc_mutex_);
883+
if (use_intra_process_) {
884+
auto ipm = weak_ipm_.lock();
885+
if (!ipm) {
886+
throw std::runtime_error(
887+
"intra process send called after destruction of intra process manager");
888+
}
889+
bool intra_process_server_available = ipm->service_is_available(intra_process_client_id_);
890+
891+
// Check if there's an intra-process server available matching this client.
892+
// If there's not, we fall back into inter-process communication, since
893+
// the server might be available in another process or was configured to not use IPC.
894+
if (intra_process_server_available) {
895+
// Send intra-process request
896+
ipm->send_intra_process_client_request<ServiceT>(
897+
intra_process_client_id_,
898+
std::make_pair(std::move(request), std::move(value)));
899+
return ipc_sequence_number_++;
900+
}
899901
}
900902
}
901903

0 commit comments

Comments
 (0)