Skip to content

Commit

Permalink
Move check_deadline to reactor.c, as it needs to know struct types, s…
Browse files Browse the repository at this point in the history
…uch as reaction_t and self_base_t which, which are defined in reactor.h.

Thus, if we put check_deadline inside util.c, it creates mutual dependency between util and reactor.
  • Loading branch information
hokeun committed Feb 12, 2022
1 parent f20ea32 commit 077a526
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 31 deletions.
18 changes: 18 additions & 0 deletions core/reactor.c
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,24 @@ void request_stop() {
_lf_set_stop_tag(new_stop_tag);
}

/**
* 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.
* @return false if the deadline has not passed yet.
*/
bool check_deadline(void* self) {
reaction_t* reaction = ((self_base_t*)self)->executing_reaction;
if (get_physical_time() > get_logical_time() + reaction->deadline) {
reaction->deadline_violation_handler(self);
return true;
}
return false;
}

/**
* Do nothing. This implementation is not multithreaded.
*/
Expand Down
19 changes: 0 additions & 19 deletions core/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "util.h"
#include "reactor.h"
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
Expand Down Expand Up @@ -218,21 +217,3 @@ void register_print_function(print_message_function_t* function, int log_level)
print_message_function = function;
print_message_level = log_level;
}

/**
* 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.
* @return false if the deadline has not passed yet.
*/
bool check_deadline(void* self) {
reaction_t* reaction = ((self_base_t*)self)->executing_reaction;
if (get_physical_time() > get_logical_time() + reaction->deadline) {
reaction->deadline_violation_handler(self);
return true;
}
return false;
}
12 changes: 0 additions & 12 deletions core/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define UTIL_H

#include <stdarg.h> // Defines va_list
#include <stdbool.h> // Defines bool

/**
* Holds generic statistical data
Expand Down Expand Up @@ -212,15 +211,4 @@ typedef void(print_message_function_t)(char*, va_list);
*/
void register_print_function(print_message_function_t* function, int log_level);

/**
* 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.
* @return false if the deadline has not passed yet.
*/
bool check_deadline(void* self);

#endif /* UTIL_H */

2 comments on commit 077a526

@Soroosh129
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think reactor_common.c is where you might want to put this function. reactor.c is only for unthreaded programs.

@Soroosh129
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another thing is that user-facing API should be defined/prototyped in ctarget.h.

Please sign in to comment.