Skip to content

Commit

Permalink
Merge pull request #38 from lf-lang/check-deadline
Browse files Browse the repository at this point in the history
Add check_deadline function.
  • Loading branch information
hokeun authored Feb 13, 2022
2 parents 25362b8 + d09316f commit 89dd926
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 0 deletions.
11 changes: 11 additions & 0 deletions core/reactor.h
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,7 @@ typedef struct allocation_record_t {
*/
typedef struct self_base_t {
struct allocation_record_t *allocations;
struct reaction_t *executing_reaction; // The currently executing reaction of the reactor.
} self_base_t;

// ======== Function Declarations ======== //
Expand Down Expand Up @@ -876,6 +877,16 @@ void _lf_notify_workers(void);
*/
bool _lf_is_blocked_by_executing_reaction(void);

/**
* Check the deadline of the currently executing reaction against the
* current physical time. If the deadline has passed, invoke the deadline
* handler and return true. Otherwise, return false.
*
* @param self The self struct of the reactor.
* @return True if the specified deadline has passed and false otherwise.
*/
bool _lf_check_deadline(self_base_t* self);

// ******** Global Variables ******** //

/**
Expand Down
17 changes: 17 additions & 0 deletions core/reactor_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -1534,6 +1534,23 @@ lf_token_t* _lf_set_new_array_impl(lf_token_t* token, size_t length, int num_des
return new_token;
}

/**
* Check the deadline of the currently executing reaction against the
* current physical time. If the deadline has passed, invoke the deadline
* handler and return true. Otherwise, return false.
*
* @param self The self struct of the reactor.
* @return True if the specified deadline has passed and false otherwise.
*/
bool _lf_check_deadline(self_base_t* self) {
reaction_t* reaction = self->executing_reaction;
if (get_physical_time() > get_logical_time() + reaction->deadline) {
reaction->deadline_violation_handler(self);
return true;
}
return false;
}

/**
* For the specified reaction, if it has produced outputs, insert the
* resulting triggered reactions into the reaction queue.
Expand Down
1 change: 1 addition & 0 deletions core/utils/vector.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target_sources(${LF_MAIN_TARGET} PRIVATE vector.c)
10 changes: 10 additions & 0 deletions include/ctarget.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,4 +252,14 @@ trigger_handle_t schedule_copy(void* action, interval_t offset, void* value, int
*/
trigger_handle_t schedule_value(void* action, interval_t extra_delay, void* value, int length);

/**
* Check the deadline of the currently executing reaction against the
* current physical time. If the deadline has passed, invoke the deadline
* handler and return true. Otherwise, return false.
*
* @param self The self struct of the reactor.
* @return True if the specified deadline has passed and false otherwise.
*/
bool check_deadline(void* self);

#endif // CTARGET_H
12 changes: 12 additions & 0 deletions lib/ctarget.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,15 @@ trigger_handle_t schedule_value(void* action, interval_t extra_delay, void* valu
}
return _lf_schedule_value(action, extra_delay, value, (size_t)length);
}

/**
* Check the deadline of the currently executing reaction against the
* current physical time. If the deadline has passed, invoke the deadline
* handler and return true. Otherwise, return false.
*
* @param self The self struct of the reactor.
* @return True if the specified deadline has passed and false otherwise.
*/
bool check_deadline(void* self) {
return _lf_check_deadline((self_base_t*)self);
}

0 comments on commit 89dd926

Please sign in to comment.