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

Various suggested updates for watchdogs branch #184

Merged
merged 3 commits into from
Mar 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 5 additions & 3 deletions core/reactor_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -1318,21 +1318,23 @@ bool _lf_check_deadline(self_base_t* self, bool invoke_deadline_handler) {

#ifdef LF_THREADED

void* run_watchdog(watchdog_t* watchdog) {
void* run_watchdog(void* arg) {
watchdog_t* watchdog = (watchdog_t*)arg;
watchdog->thread_active = true;
self_base_t* base = watchdog->base;
lf_mutex_lock(&(base->watchdog_mutex));

while (lf_time_physical() < watchdog->expiration) {
interval_t T = watchdog->expiration - lf_time_physical();
lf_mutex_unlock(&(base->watchdog_mutex));
lf_nanosleep(T);
lf_sleep(T);
lf_mutex_lock(&(base->watchdog_mutex));
}
watchdog_function_t watchdog_func = watchdog->watchdog_function;
(*watchdog_func)(watchdog);
(*watchdog_func)(base);
lf_mutex_unlock(&(base->watchdog_mutex));
watchdog->thread_active = false;
return NULL;
}

void _lf_watchdog_start(watchdog_t* watchdog, interval_t additional_timeout) {
Expand Down
10 changes: 5 additions & 5 deletions include/core/lf_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ typedef void(*reaction_function_t)(void*);
* these watchdog functions is a pointer to the self struct
* for the reactor.
*/
typedef void(*watchdog_function_t)(void*);
typedef void(*watchdog_function_t)(void*);

/** Trigger struct representing an output, timer, action, or input. See below. */
typedef struct trigger_t trigger_t;
Expand Down Expand Up @@ -223,12 +223,12 @@ typedef struct watchdog_t watchdog_t;
#ifdef LF_THREADED
/** Watchdog struct for handler. */
struct watchdog_t {
struct self_base_t* base; // The reactor that contains the watchdog.
struct self_base_t* base; // The reactor that contains the watchdog.
instant_t expiration; // The expiration instant for the watchdog. (Initialized to NEVER)
interval_t min_expiration; // The minimum expiration interval for the watchdog.
lf_thread_t thread_id; // The thread that the watchdog is meant to run on.
bool thread_active; // Boolean indicating whether or not thread is active.
watchdog_function_t watchdog_function; // The function/handler for the watchdog.
lf_thread_t thread_id; // The thread that the watchdog is meant to run on.
bool thread_active; // Boolean indicating whether or not thread is active.
watchdog_function_t watchdog_function; // The function/handler for the watchdog.
};
#endif

Expand Down
2 changes: 1 addition & 1 deletion include/core/reactor_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void _lf_advance_logical_time(instant_t next_time);
trigger_handle_t _lf_schedule_int(lf_action_base_t* action, interval_t extra_delay, int value);
bool _lf_check_deadline(self_base_t* self, bool invoke_deadline_handler);
#ifdef LF_THREADED
void* run_watchdog(watchdog_t* watchdog);
void* run_watchdog(void* watchdog);
void _lf_watchdog_start(watchdog_t* watchdog, interval_t additional_timeout);
void _lf_watchdog_stop(watchdog_t* watchdog);
#endif
Expand Down