Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make SET work with both token and non-token types #66

Merged
merged 44 commits into from
Apr 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
ac76c22
add destructor field to token
housengw Apr 11, 2022
efca0b5
refactor free token functions
housengw Apr 11, 2022
f358e43
remove 'elem_size' from SET_ARRAY APIs
housengw Apr 12, 2022
32e777b
add destructor variant of SET
housengw Apr 12, 2022
855fbe9
bug fix
housengw Apr 12, 2022
7e3a36c
set ok_to_free to 'token_and_value' in _LF_SET_DYNAMIC
housengw Apr 12, 2022
2fbfe4f
apply suggestions from code review
housengw Apr 13, 2022
0f1f415
add SET_DESTRUCTOR and SET_COPY_CONSTRUCTOR APIs
housengw Apr 15, 2022
3b20499
update SET API
housengw Apr 16, 2022
032f271
make SET work with both token and non-token types
housengw Apr 17, 2022
4b2e54b
remove SET_DYNAMIC
housengw Apr 18, 2022
e83968e
add comments for SET_DESTRUCTOR and SET_COPY_CONSTRUCTOR
housengw Apr 18, 2022
58d8768
make SET_COPY_CONSTRUCTOR take output port instead of input port
housengw Apr 18, 2022
d85e921
add comments to user-facing SET_DESTRUCTOR and SET_COPY_CONSTRUCTOR
housengw Apr 19, 2022
ab42775
add lowercase variants of SETs and deprecate uppercase versions
housengw Apr 19, 2022
9f49a15
add #undef file for ctarget macros to prevent naming collisions
housengw Apr 19, 2022
3261932
prevent duplicate definition of schedule functions
housengw Apr 19, 2022
bd88690
update author info
housengw Apr 19, 2022
6e35c0b
move #include in ctarget.h
housengw Apr 19, 2022
d21dc5e
factor ctarget.h into schedule and set subfiles
housengw Apr 20, 2022
247e0c3
change up-to-date api to 'lf_' prefixed names
housengw Apr 20, 2022
42d3665
add 'lf_' prefix to schedule functions
housengw Apr 20, 2022
9069512
move DEPRECATED macro to platform.h
housengw Apr 20, 2022
e90fd25
add lf_ to schedule_int
housengw Apr 20, 2022
fa1599a
rename tag API
housengw Apr 20, 2022
5a75995
do not rename APIs that can be replaced by lf_set
housengw Apr 21, 2022
e13e50c
Merge branch 'schedule-lf-prefix' into deprecate-uppercase-set
housengw Apr 21, 2022
c04636a
Merge branch 'tag-lf-prefix' into deprecate-uppercase-set
housengw Apr 21, 2022
7e9c673
change internal tag functions to _lf prefix
housengw Apr 22, 2022
8005233
first implementation of lf_tag and lf_time
housengw Apr 22, 2022
182d7d3
apply suggestion from code review
housengw Apr 22, 2022
edea132
do not allow lf_time_flag as argument to lf_tag
housengw Apr 22, 2022
94d7eba
change references of compare_tags to lf_compare_tags
housengw Apr 22, 2022
b6a3830
replace references of get_current_tag() to lf_tag()
housengw Apr 22, 2022
19638f3
update ci file to point to deprecate-uppercase-set
housengw Apr 22, 2022
b657dbe
replace deprecated API references to up-to-date ones
housengw Apr 22, 2022
9e17f8a
update cmake lists for unit tests
housengw Apr 22, 2022
b871004
update lingua-franca-ref.txt
housengw Apr 22, 2022
fc7dc8a
Merge pull request #68 from lf-lang/deprecate-uppercase-set
housengw Apr 25, 2022
7d0c6d7
merge main into branch
housengw Apr 25, 2022
f9d1e98
update github action files
housengw Apr 25, 2022
93701bf
update references to deprecated API
housengw Apr 25, 2022
a5114c6
apply suggestions from code review
housengw Apr 26, 2022
fd033e1
update lingua-franca-ref
housengw Apr 26, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,28 @@ jobs:
cmake-args: '-DNUMBER_OF_WORKERS=4'

fetch-lf:
uses: lf-lang/lingua-franca/.github/workflows/extract-ref.yml@master
uses: lf-lang/lingua-franca/.github/workflows/extract-ref.yml@set-destructor-variant
with:
file: 'lingua-franca-ref.txt'

lf-default:
needs: fetch-lf
uses: lf-lang/lingua-franca/.github/workflows/c-tests.yml@master
uses: lf-lang/lingua-franca/.github/workflows/c-tests.yml@set-destructor-variant
with:
runtime-ref: ${{ github.ref }}
compiler-ref: ${{ needs.fetch-lf.outputs.ref }}

lf-gedf-np:
needs: fetch-lf
uses: lf-lang/lingua-franca/.github/workflows/c-tests.yml@master
uses: lf-lang/lingua-franca/.github/workflows/c-tests.yml@set-destructor-variant
with:
runtime-ref: ${{ github.ref }}
compiler-ref: ${{ needs.fetch-lf.outputs.ref }}
scheduler: GEDF_NP

lf-gedf-np-ci:
needs: fetch-lf
uses: lf-lang/lingua-franca/.github/workflows/c-tests.yml@master
uses: lf-lang/lingua-franca/.github/workflows/c-tests.yml@set-destructor-variant
with:
runtime-ref: ${{ github.ref }}
compiler-ref: ${{ needs.fetch-lf.outputs.ref }}
Expand Down
50 changes: 25 additions & 25 deletions core/federated/RTI/rti.c
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ void handle_timed_message(federate_t* sending_federate, unsigned char* buffer) {
// is a promise that is valid only in the absence of network inputs,
// and now there is a network input. Hence, the promise needs to be
// updated.
if (compare_tags(_RTI.federates[federate_id].next_event, intended_tag) > 0) {
if (lf_compare_tags(_RTI.federates[federate_id].next_event, intended_tag) > 0) {
_RTI.federates[federate_id].next_event = intended_tag;
}

Expand Down Expand Up @@ -400,8 +400,8 @@ void handle_timed_message(federate_t* sending_federate, unsigned char* buffer) {
*/
void send_tag_advance_grant(federate_t* fed, tag_t tag) {
if (fed->state == NOT_CONNECTED
|| compare_tags(tag, fed->last_granted) <= 0
|| compare_tags(tag, fed->last_provisionally_granted) < 0
|| lf_compare_tags(tag, fed->last_granted) <= 0
|| lf_compare_tags(tag, fed->last_provisionally_granted) < 0
) {
return;
}
Expand Down Expand Up @@ -463,7 +463,7 @@ tag_t transitive_next_event(federate_t* fed, tag_t candidate, bool visited[]) {
tag_t result = fed->next_event;

// If the candidate is less than this federate's next_event, use the candidate.
if (compare_tags(candidate, result) < 0) {
if (lf_compare_tags(candidate, result) < 0) {
result = candidate;
}

Expand All @@ -480,14 +480,14 @@ tag_t transitive_next_event(federate_t* fed, tag_t candidate, bool visited[]) {
&_RTI.federates[fed->upstream[i]], result, visited);

// Add the "after" delay of the connection to the result.
upstream_result = delay_tag(upstream_result, fed->upstream_delay[i]);
upstream_result = _lf_delay_tag(upstream_result, fed->upstream_delay[i]);

// If the adjusted event time is less than the result so far, update the result.
if (compare_tags(upstream_result, result) < 0) {
if (lf_compare_tags(upstream_result, result) < 0) {
result = upstream_result;
}
}
if (compare_tags(result, fed->completed) < 0) {
if (lf_compare_tags(result, fed->completed) < 0) {
result = fed->completed;
}
return result;
Expand All @@ -507,8 +507,8 @@ tag_t transitive_next_event(federate_t* fed, tag_t candidate, bool visited[]) {
*/
void send_provisional_tag_advance_grant(federate_t* fed, tag_t tag) {
if (fed->state == NOT_CONNECTED
|| compare_tags(tag, fed->last_granted) <= 0
|| compare_tags(tag, fed->last_provisionally_granted) <= 0
|| lf_compare_tags(tag, fed->last_granted) <= 0
|| lf_compare_tags(tag, fed->last_provisionally_granted) <= 0
|| (tag.time == start_time && tag.microstep == 0) // PTAG at (0,0) is implicit
) {
return;
Expand Down Expand Up @@ -558,7 +558,7 @@ void send_provisional_tag_advance_grant(federate_t* fed, tag_t tag) {
// a TAG or PTAG should have already been granted,
// in which case, another will not be sent. But it
// may not have been already granted.
if (compare_tags(upstream_next_event, tag) >= 0) {
if (lf_compare_tags(upstream_next_event, tag) >= 0) {
send_provisional_tag_advance_grant(upstream, tag);
}
}
Expand Down Expand Up @@ -605,17 +605,17 @@ bool send_advance_grant_if_safe(federate_t* fed) {
// Ignore this federate if it has resigned.
if (upstream->state == NOT_CONNECTED) continue;

tag_t candidate = delay_tag(upstream->completed, fed->upstream_delay[j]);
tag_t candidate = _lf_delay_tag(upstream->completed, fed->upstream_delay[j]);

if (compare_tags(candidate, min_upstream_completed) < 0) {
if (lf_compare_tags(candidate, min_upstream_completed) < 0) {
min_upstream_completed = candidate;
}
}
LOG_PRINT("Minimum upstream LTC for fed %d is (%lld, %u) "
"(adjusted by after delay).",
fed->id,
min_upstream_completed.time - start_time, min_upstream_completed.microstep);
if (compare_tags(min_upstream_completed, fed->last_granted) > 0) {
if (lf_compare_tags(min_upstream_completed, fed->last_granted) > 0) {
send_tag_advance_grant(fed, min_upstream_completed);
return true;
}
Expand Down Expand Up @@ -656,17 +656,17 @@ bool send_advance_grant_if_safe(federate_t* fed) {
// Adjust by the "after" delay.
// Note that "no delay" is encoded as NEVER,
// whereas one microstep delay is encoded as 0LL.
tag_t candidate = delay_tag(upstream_next_event, fed->upstream_delay[j]);
tag_t candidate = _lf_delay_tag(upstream_next_event, fed->upstream_delay[j]);

if (compare_tags(candidate, t_d) < 0) {
if (lf_compare_tags(candidate, t_d) < 0) {
t_d = candidate;
}
}

LOG_PRINT("Earliest next event upstream has tag (%lld, %u).",
t_d.time - start_time, t_d.microstep);

if (compare_tags(t_d, FOREVER_TAG) == 0) {
if (lf_compare_tags(t_d, FOREVER_TAG) == 0) {
// Upstream federates are all done.
LOG_PRINT("Upstream federates are all done. Granting tag advance.");
send_tag_advance_grant(fed, FOREVER_TAG);
Expand All @@ -678,9 +678,9 @@ bool send_advance_grant_if_safe(federate_t* fed) {
send_tag_advance_grant(fed, FOREVER_TAG);
return true;
} else if (
compare_tags(t_d, fed->next_event) >= 0 // The federate has something to do.
&& compare_tags(t_d, fed->last_provisionally_granted) > 0 // The grant is not redundant.
&& compare_tags(t_d, fed->last_granted) > 0 // The grant is not redundant.
lf_compare_tags(t_d, fed->next_event) >= 0 // The federate has something to do.
&& lf_compare_tags(t_d, fed->last_provisionally_granted) > 0 // The grant is not redundant.
&& lf_compare_tags(t_d, fed->last_granted) > 0 // The grant is not redundant.
) {
LOG_PRINT("Earliest upstream message time for fed %d is (%lld, %u) "
"(adjusted by after delay). Granting provisional tag advance.",
Expand Down Expand Up @@ -812,7 +812,7 @@ void handle_time_advance_notice(federate_t* fed) {
// network inputs, the federate will not produce an output with tag
// less than the NET.
tag_t ta = (tag_t) {.time = fed->time_advance, .microstep = 0};
if (compare_tags(ta, fed->next_event) > 0) {
if (lf_compare_tags(ta, fed->next_event) > 0) {
fed->next_event = ta;
// We need to reply just as if this were a NET because it could unblock
// network input port control reactions.
Expand Down Expand Up @@ -860,7 +860,7 @@ void _lf_rti_broadcast_stop_time_to_federates_already_locked() {
if (_RTI.federates[i].state == NOT_CONNECTED) {
continue;
}
if (compare_tags(_RTI.federates[i].next_event, _RTI.max_stop_tag) >= 0) {
if (lf_compare_tags(_RTI.federates[i].next_event, _RTI.max_stop_tag) >= 0) {
// Need the next_event to be no greater than the stop tag.
_RTI.federates[i].next_event = _RTI.max_stop_tag;
}
Expand Down Expand Up @@ -930,7 +930,7 @@ void handle_stop_request_message(federate_t* fed) {
tag_t proposed_stop_tag = extract_tag(buffer);

// Update the maximum stop tag received from federates
if (compare_tags(proposed_stop_tag, _RTI.max_stop_tag) > 0) {
if (lf_compare_tags(proposed_stop_tag, _RTI.max_stop_tag) > 0) {
_RTI.max_stop_tag = proposed_stop_tag;
}

Expand Down Expand Up @@ -993,7 +993,7 @@ void handle_stop_request_reply(federate_t* fed) {
// Acquire the mutex lock so that we can change the state of the RTI
pthread_mutex_lock(&_RTI.rti_mutex);
// If the federate has not requested stop before, count the reply
if (compare_tags(federate_stop_tag, _RTI.max_stop_tag) > 0) {
if (lf_compare_tags(federate_stop_tag, _RTI.max_stop_tag) > 0) {
_RTI.max_stop_tag = federate_stop_tag;
}
mark_federate_requesting_stop(fed);
Expand Down Expand Up @@ -1163,7 +1163,7 @@ void send_physical_clock(unsigned char message_type, federate_t* fed, socket_typ
}
unsigned char buffer[sizeof(int64_t) + 1];
buffer[0] = message_type;
int64_t current_physical_time = get_physical_time();
int64_t current_physical_time = lf_time(LF_PHYSICAL);
encode_int64(current_physical_time, &(buffer[1]));

// Send the message
Expand Down Expand Up @@ -1240,7 +1240,7 @@ void* clock_synchronization_thread(void* noargs) {

// Wait until the start time before starting clock synchronization.
// The above wait ensures that start_time has been set.
interval_t ns_to_wait = start_time - get_physical_time();
interval_t ns_to_wait = start_time - lf_time(LF_PHYSICAL);

if (ns_to_wait > 0LL) {
struct timespec wait_time = {ns_to_wait / BILLION, ns_to_wait % BILLION};
Expand Down
10 changes: 5 additions & 5 deletions core/federated/clock-sync.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ void synchronize_initial_physical_clock_with_rti(int rti_socket_TCP) {
_lf_my_fed_id);

// Get local physical time before doing anything else.
instant_t receive_time = get_physical_time();
instant_t receive_time = lf_time(LF_PHYSICAL);

// Check that this is the T1 message.
if (buffer[0] != MSG_TYPE_CLOCK_SYNC_T1) {
Expand Down Expand Up @@ -287,7 +287,7 @@ int handle_T1_clock_sync_message(unsigned char* buffer, int socket, instant_t t2
// Measure the time _after_ the write on the assumption that the read
// from the socket, which occurs before this function is called, takes
// about the same amount of time as the write of the reply.
_lf_rti_socket_stat.local_delay = get_physical_time() - t2;
_lf_rti_socket_stat.local_delay = lf_time(LF_PHYSICAL) - t2;
return 0;
}

Expand Down Expand Up @@ -346,7 +346,7 @@ void handle_T4_clock_sync_message(unsigned char* buffer, int socket, instant_t r
// We can reuse the same buffer.
ssize_t bytes_read = read_from_socket(socket, 1 + sizeof(instant_t), buffer);

instant_t r5 = get_physical_time();
instant_t r5 = lf_time(LF_PHYSICAL);

if ((bytes_read < 1 + (ssize_t)sizeof(instant_t))
|| buffer[0] != MSG_TYPE_CLOCK_SYNC_CODED_PROBE) {
Expand Down Expand Up @@ -380,7 +380,7 @@ void handle_T4_clock_sync_message(unsigned char* buffer, int socket, instant_t r
}
// Apply a jitter attenuator to the estimated clock error to prevent
// large jumps in the underlying clock.
// Note that estimated_clock_error is calculated using get_physical_time() which includes
// Note that estimated_clock_error is calculated using lf_time(LF_PHYSICAL) which includes
// the _lf_global_physical_clock_offset adjustment.
adjustment = estimated_clock_error / _LF_CLOCK_SYNC_ATTENUATION;

Expand Down Expand Up @@ -485,7 +485,7 @@ void* listen_to_rti_UDP_thread(void* args) {
} while ((errno == EAGAIN || errno == EWOULDBLOCK) && bytes_read < message_size);

// Get local physical time before doing anything else.
instant_t receive_time = get_physical_time();
instant_t receive_time = lf_time(LF_PHYSICAL);

if (bytes_read < message_size) {
// Either the socket has closed or the RTI has sent EOF.
Expand Down
Loading