Skip to content

Commit

Permalink
Merge branch 'main' into shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardalee authored Feb 12, 2025
2 parents 7f0ad69 + 8072355 commit 89f7b91
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
7 changes: 5 additions & 2 deletions core/federated/federate.c
Original file line number Diff line number Diff line change
Expand Up @@ -1957,10 +1957,13 @@ void lf_connect_to_rti(const char* hostname, int port) {

void lf_create_server(int specified_port) {
assert(specified_port <= UINT16_MAX && specified_port >= 0);
if (create_server(specified_port, &_fed.server_socket, (uint16_t*)&_fed.server_port, TCP, false)) {
uint16_t final_port;
if (create_server(specified_port, &_fed.server_socket, &final_port, TCP, false)) {
lf_print_error_system_failure("RTI failed to create TCP server: %s.", strerror(errno));
};
LF_PRINT_LOG("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 %u.", final_port);
_fed.server_port = final_port;

// Send the server port number to the RTI
// on an MSG_TYPE_ADDRESS_ADVERTISEMENT message (@see net_common.h).
Expand Down
5 changes: 2 additions & 3 deletions core/threaded/reactor_threaded.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,8 @@ bool wait_until(instant_t wait_until_time, lf_cond_t* condition) {
LF_PRINT_DEBUG("-------- Waiting until physical time " PRINTF_TIME, wait_until_time - start_time);
// Check whether we actually need to wait, or if we have already passed the timepoint.
interval_t wait_duration = wait_until_time - lf_time_physical();
if (wait_duration < MIN_SLEEP_DURATION) {
LF_PRINT_DEBUG("Wait time " PRINTF_TIME " is less than MIN_SLEEP_DURATION " PRINTF_TIME ". Skipping wait.",
wait_duration, MIN_SLEEP_DURATION);
if (wait_duration < 0) {
LF_PRINT_DEBUG("We have already passed " PRINTF_TIME ". Skipping wait.", wait_until_time);
return true;
}

Expand Down
4 changes: 2 additions & 2 deletions include/core/threaded/reactor_threaded.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ void lf_synchronize_with_other_federates(void);
* if that event time matches or exceeds the specified time.
*
* The mutex lock associated with the condition argument is assumed to be held by
* the calling thread. This mutex is released while waiting. If the wait time is
* too small to actually wait (less than MIN_SLEEP_DURATION), then this function
* the calling thread. This mutex is released while waiting. If the current physical
* time has already passed the specified time, then this function
* immediately returns true and the mutex is not released.
*
* @param env Environment within which we are executing.
Expand Down
9 changes: 6 additions & 3 deletions util/sensor_simulator.c
Original file line number Diff line number Diff line change
Expand Up @@ -347,13 +347,16 @@ void end_sensor_simulator() {
lf_register_print_function(NULL, -1);
_lf_sensor_post_message(_lf_sensor_close_windows, NULL);

void* thread_return;
lf_thread_join(_lf_sensor.output_thread_id, &thread_return);
// Join thread, if it was created and it was not already joined.
if (_lf_sensor.thread_created > 0) {
void* thread_return;
lf_thread_join(_lf_sensor.output_thread_id, &thread_return);
_lf_sensor.thread_created = 0;
}

// Timeout mode should result in the input thread exiting on its own.
// pthread_kill(_lf_sensor.input_thread_id, SIGINT);

_lf_sensor.thread_created = 0;
if (_lf_sensor.log_file != NULL) {
fclose(_lf_sensor.log_file);
}
Expand Down

0 comments on commit 89f7b91

Please sign in to comment.