Skip to content

Commit

Permalink
Remove some unnecessary mutex locks from RTI and federate.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakio815 committed Mar 5, 2025
1 parent d576728 commit 72682d6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions core/federated/RTI/rti_remote.c
Original file line number Diff line number Diff line change
Expand Up @@ -970,9 +970,9 @@ void* federate_info_thread_TCP(void* fed) {
my_fed->enclave.state = NOT_CONNECTED;
// Nothing more to do. Close the socket and exit.
// Prevent multiple threads from closing the same socket at the same time.
LF_MUTEX_LOCK(&rti_mutex);
// LF_MUTEX_LOCK(&rti_mutex);
shutdown_socket(&my_fed->socket, false); // from unistd.h
LF_MUTEX_UNLOCK(&rti_mutex);
// LF_MUTEX_UNLOCK(&rti_mutex);
// FIXME: We need better error handling here, but do not stop execution here.
break;
}
Expand Down Expand Up @@ -1030,14 +1030,14 @@ void send_reject(int* socket_id, unsigned char error_code) {
unsigned char response[2];
response[0] = MSG_TYPE_REJECT;
response[1] = error_code;
LF_MUTEX_LOCK(&rti_mutex);
// LF_MUTEX_LOCK(&rti_mutex);
// NOTE: Ignore errors on this response.
if (write_to_socket(*socket_id, 2, response)) {
lf_print_warning("RTI failed to write MSG_TYPE_REJECT message on the socket.");
}
// Close the socket without reading until EOF.
shutdown_socket(socket_id, false);
LF_MUTEX_UNLOCK(&rti_mutex);
// LF_MUTEX_UNLOCK(&rti_mutex);
}

/**
Expand Down
12 changes: 6 additions & 6 deletions core/federated/federate.c
Original file line number Diff line number Diff line change
Expand Up @@ -417,11 +417,11 @@ static trigger_handle_t schedule_message_received_from_network_locked(environmen
* federate.
*/
static void close_inbound_socket(int fed_id) {
LF_MUTEX_LOCK(&lf_inbound_socket_mutex);
// LF_MUTEX_LOCK(&lf_inbound_socket_mutex);
if (_fed.sockets_for_inbound_p2p_connections[fed_id] >= 0) {
shutdown_socket(&_fed.sockets_for_inbound_p2p_connections[fed_id], false);
}
LF_MUTEX_UNLOCK(&lf_inbound_socket_mutex);
// LF_MUTEX_UNLOCK(&lf_inbound_socket_mutex);
}

/**
Expand Down Expand Up @@ -831,13 +831,13 @@ static void close_outbound_socket(int fed_id) {
// This will result in EOF being sent to the remote federate, except for
// abnormal termination, in which case it will just close the socket.
if (_lf_normal_termination) {
LF_MUTEX_LOCK(&lf_outbound_socket_mutex);
// LF_MUTEX_LOCK(&lf_outbound_socket_mutex);
if (_fed.sockets_for_outbound_p2p_connections[fed_id] >= 0) {
// Close the socket by sending a FIN packet indicating that no further writes
// are expected. Then read until we get an EOF indication.
shutdown_socket(&_fed.sockets_for_outbound_p2p_connections[fed_id], true);
}
LF_MUTEX_UNLOCK(&lf_outbound_socket_mutex);
// LF_MUTEX_UNLOCK(&lf_outbound_socket_mutex);
} else {
shutdown_socket(&_fed.sockets_for_outbound_p2p_connections[fed_id], false);
}
Expand Down Expand Up @@ -2093,12 +2093,12 @@ void* lf_handle_p2p_connections_from_federates(void* env_arg) {
int result = lf_thread_create(&_fed.inbound_socket_listeners[received_federates], listen_to_federates, fed_id_arg);
if (result != 0) {
// Failed to create a listening thread.
LF_MUTEX_LOCK(&lf_inbound_socket_mutex);
// LF_MUTEX_LOCK(&lf_inbound_socket_mutex);
if (_fed.sockets_for_inbound_p2p_connections[remote_fed_id] != -1) {
shutdown_socket(&socket_id, false);
_fed.sockets_for_inbound_p2p_connections[remote_fed_id] = -1;
}
LF_MUTEX_UNLOCK(&lf_inbound_socket_mutex);
// LF_MUTEX_UNLOCK(&lf_inbound_socket_mutex);
lf_print_error_and_exit("Failed to create a thread to listen for incoming physical connection. Error code: %d.",
result);
}
Expand Down

0 comments on commit 72682d6

Please sign in to comment.