Skip to content

Commit

Permalink
Response to code review
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardalee committed Jun 29, 2023
1 parent 6218e18 commit b9a27d9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
24 changes: 10 additions & 14 deletions core/federated/federate.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ federate_instance_t _fed = {
.waiting_for_TAG = false,
.has_upstream = false,
.has_downstream = false,
.sent_a_stop_request_to_rti = false,
.received_stop_request_from_rti = false,
.last_sent_LTC = (tag_t) {.time = NEVER, .microstep = 0u},
.last_sent_NET = (tag_t) {.time = NEVER, .microstep = 0u},
.min_delay_from_physical_action_to_federate_output = NEVER,
Expand Down Expand Up @@ -2278,12 +2278,8 @@ void _lf_fd_send_stop_request_to_rti(tag_t stop_tag) {
ENCODE_STOP_REQUEST(buffer, stop_tag.time, stop_tag.microstep + 1);

lf_mutex_lock(&outbound_socket_mutex);
// Do not send a stop request twice.
// Also, if we have received a stop request from the RTI, do not send this one
// because we have already blocked tag advance.
// The latter occurs if some other federate has requested a stop.
if (!_fed.sent_a_stop_request_to_rti) {
_fed.sent_a_stop_request_to_rti = true;
// Do not send a stop request if a stop request has been previously received from the RTI.
if (!_fed.received_stop_request_from_rti) {
LF_PRINT_LOG("Sending to RTI a MSG_TYPE_STOP_REQUEST message with tag " PRINTF_TAG ".",
stop_tag.time - start_time,
stop_tag.microstep);
Expand Down Expand Up @@ -2311,7 +2307,7 @@ void _lf_fd_send_stop_request_to_rti(tag_t stop_tag) {
lf_mutex_unlock(&env[i].mutex);
}
}
}
}

/**
* Handle a MSG_TYPE_STOP_GRANTED message from the RTI.
Expand Down Expand Up @@ -2380,18 +2376,18 @@ void handle_stop_request_message() {
tag_to_stop.time - start_time,
tag_to_stop.microstep);

// If we have previously sent to the RTI a stop request
// or we have previously received from the RTI a stop request,
// If we have previously received from the RTI a stop request,
// then we have already blocked tag advance in enclaves.
// Do not do this twice.
// The record of whether this has occurred
// Do not do this twice. The record of whether this has occurred
// is guarded by the outbound socket mutex.
// Note that this should not occur; the RTI should avoid sending
// stop requests more than once to federates.
lf_mutex_lock(&outbound_socket_mutex);
bool already_blocked = false;
if (_fed.sent_a_stop_request_to_rti) {
if (_fed.received_stop_request_from_rti) {
already_blocked = true;
}
_fed.sent_a_stop_request_to_rti = true;
_fed.received_stop_request_from_rti = true;
lf_mutex_unlock(&outbound_socket_mutex);

// Iterate over the scheduling enclaves to find the maximum current tag
Expand Down
4 changes: 2 additions & 2 deletions include/core/federated/federate.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,10 @@ typedef struct federate_instance_t {

/**
* Used to prevent the federate from sending a REQUEST_STOP
* message multiple times to the RTI.
* message if it has already received a stop request from the RTI.
* This variable should only be accessed while holding a mutex lock.
*/
bool sent_a_stop_request_to_rti;
bool received_stop_request_from_rti;

/**
* A record of the most recently sent LTC (logical tag complete) message.
Expand Down

0 comments on commit b9a27d9

Please sign in to comment.