Skip to content

Commit

Permalink
Fix to only use shutdown_mutex internally in socket_common.c, and cre…
Browse files Browse the repository at this point in the history
…ate a function to call the initialize of the mutex.
  • Loading branch information
Jakio815 committed Mar 5, 2025
1 parent 618989d commit d576728
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion core/federated/RTI/rti_remote.c
Original file line number Diff line number Diff line change
Expand Up @@ -1563,7 +1563,7 @@ void initialize_RTI(rti_remote_t* rti) {

// Initialize thread synchronization primitives
LF_MUTEX_INIT(&rti_mutex);
LF_MUTEX_INIT(&shutdown_mutex);
init_shutdown_mutex();
LF_COND_INIT(&received_start_times, &rti_mutex);
LF_COND_INIT(&sent_start_time, &rti_mutex);

Expand Down
2 changes: 2 additions & 0 deletions core/federated/network/socket_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,8 @@ void write_to_socket_fail_on_error(int* socket, size_t num_bytes, unsigned char*
}
}

void init_shutdown_mutex(void) { LF_MUTEX_INIT(&shutdown_mutex); }

int shutdown_socket(int* socket, bool read_before_closing) {
LF_MUTEX_LOCK(&shutdown_mutex);
if (*socket == -1) {
Expand Down
10 changes: 5 additions & 5 deletions include/core/federated/network/socket_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,6 @@

typedef enum socket_type_t { TCP, UDP } socket_type_t;

/**
* Mutex protecting socket shutdown operations.
*/
extern lf_mutex_t shutdown_mutex;

/**
* @brief Create an IPv4 TCP socket with Nagle's algorithm disabled
* (TCP_NODELAY) and Delayed ACKs disabled (TCP_QUICKACK). Exits application
Expand Down Expand Up @@ -240,6 +235,11 @@ int write_to_socket_close_on_error(int* socket, size_t num_bytes, unsigned char*
void write_to_socket_fail_on_error(int* socket, size_t num_bytes, unsigned char* buffer, lf_mutex_t* mutex,
char* format, ...);

/**
* Initialize shutdown mutex.
*/
void init_shutdown_mutex(void);

/**
* Shutdown and close the socket. If read_before_closing is false, it just immediately calls shutdown() with SHUT_RDWR
* and close(). If read_before_closing is true, it calls shutdown with SHUT_WR, only disallowing further writing. Then,
Expand Down

0 comments on commit d576728

Please sign in to comment.