Skip to content

Commit

Permalink
Removed all tmp code and reviewed
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardalee committed Dec 20, 2023
1 parent bcea8cc commit 8a5c296
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 14 deletions.
7 changes: 4 additions & 3 deletions core/federated/RTI/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,13 @@ const char *rti_trace_file_name = "rti.lft";
bool normal_termination = false;

/**
* @brief Function to run upon abnormal termination.
* This function will be invoked both after main() returns, and when a signal
* @brief Function to run upon termination.
* This function will be invoked both after main() returns and when a signal
* that results in terminating the process, such as SIGINT. In the former
* case, it should do nothing. In the latter case, it will attempt to write
* the trace file, but without acquiring a mutex lock, so the resulting files
* may be incomplete or even corrupted.
* may be incomplete or even corrupted. But this is better than just failing
* to write the data we have collected so far.
*/
void termination() {
if (!normal_termination) {
Expand Down
4 changes: 1 addition & 3 deletions core/federated/RTI/rti_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,7 @@ void update_min_delays_upstream(scheduling_node_t* node) {

// Put the results onto the node's struct.
node->num_min_delays = count;
// FIXME: What should the newly allocated `min_delays` be initialized to?
// currently it could be any value.
node->min_delays = (minimum_delay_t*)malloc(count * sizeof(minimum_delay_t));
node->min_delays = (minimum_delay_t*)calloc(count, sizeof(minimum_delay_t));
LF_PRINT_DEBUG("++++ Node %hu(is in ZDC: %d\n", node->id, node->flags & IS_IN_ZERO_DELAY_CYCLE);
int k = 0;
for (int i = 0; i < rti_common->number_of_scheduling_nodes; i++) {
Expand Down
4 changes: 1 addition & 3 deletions core/federated/RTI/rti_remote.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,7 @@ extern int lf_critical_section_exit(environment_t* env);
/**
* Create a server and enable listening for socket connections.
*
* @note This function is similar to create_server(...) in
* federate.c. However, it contains logs that are specific
* to the RTI.
* @note This function is different from create_server(...) in federate.c.
*
* @param port The port number to use.
* @param socket_type The type of the socket for the server (TCP or UDP).
Expand Down
6 changes: 3 additions & 3 deletions core/federated/federate.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ federation_metadata_t federation_metadata = {
.rti_user = NULL
};

void create_server(int specified_port, int id) {
void create_server(int specified_port) {
assert(specified_port <= UINT16_MAX && specified_port >= 0);
uint16_t port = (uint16_t)specified_port;
LF_PRINT_LOG("Creating a socket server on port %d.", port);
Expand Down Expand Up @@ -166,7 +166,7 @@ void create_server(int specified_port, int id) {
// which according to the Mac man page is limited to 128.
listen(socket_descriptor, 128);

lf_print("Server for communicating with other federates started using port %d.", _fed.server_port);
LF_PRINT_LOG("Server for communicating with other federates started using port %d.", _fed.server_port);

// Send the server port number to the RTI
// on an MSG_TYPE_ADDRESS_ADVERTISEMENT message (@see net_common.h).
Expand Down Expand Up @@ -2279,7 +2279,7 @@ void terminate_execution(environment_t* env) {
assert(env != GLOBAL_ENVIRONMENT);

// For an abnormal termination (e.g. a SIGINT), we need to send a
// MSG_TYPE_RESIGN message to the RTI, but we should not trace it.
// MSG_TYPE_RESIGN message to the RTI, but we should not acquire a mutex.
if (_fed.socket_TCP_RTI >= 0) {
if (_lf_normal_termination) {
lf_mutex_lock(&outbound_socket_mutex);
Expand Down
3 changes: 1 addition & 2 deletions include/core/federated/federate.h
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,8 @@ void* listen_to_federates(void*);
* @note This function is different from create_server(...) in rti.c.
*
* @param specified_port The specified port by the user or 0 to use a random port.
* @param id The id of the federate (to help find a unique port).
*/
void create_server(int specified_port, int id);
void create_server(int specified_port);

/**
* Thread to accept connections from other federates that send this federate
Expand Down

0 comments on commit 8a5c296

Please sign in to comment.