From 3b7073d16aa842d7fc31903680f9579f434cf1c2 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Sun, 11 Apr 2021 18:58:16 -0500 Subject: [PATCH] Update: cleanup @todo/@fixme that no longer matter and implement multistep thread wait timeout. --- level_3/controller/c/controller.h | 3 --- level_3/controller/c/private-common.c | 20 +++++++++++++++++++- level_3/controller/c/private-common.h | 19 ++++++++++++------- level_3/controller/c/private-thread.c | 4 +--- 4 files changed, 32 insertions(+), 14 deletions(-) diff --git a/level_3/controller/c/controller.h b/level_3/controller/c/controller.h index 920f4d6..3d35094 100644 --- a/level_3/controller/c/controller.h +++ b/level_3/controller/c/controller.h @@ -15,9 +15,6 @@ * This would then allow for switching modes. * * @fixme the entire program needs to check the return status on all locks (mutex, r/w locks, etc..) and if there is a problem, print a message and wait (but ideally allow for signals, if enabled). - * - * @todo This currently only exits on memory error. - * For a production "init" program, this should continue to run...so it needs to sleep and wait for resources to become available. */ #ifndef _controller_h diff --git a/level_3/controller/c/private-common.c b/level_3/controller/c/private-common.c index 7dace55..efa6fd0 100644 --- a/level_3/controller/c/private-common.c +++ b/level_3/controller/c/private-common.c @@ -231,10 +231,23 @@ extern "C" { f_status_t status = F_none; + uint8_t count = 0; + do { f_thread_mutex_lock(&process->wait_lock); - controller_time(controller_thread_wait_timeout_seconds, controller_thread_wait_timeout_nanoseconds, &time); + if (count < controller_thread_wait_timeout_1_before) { + controller_time(controller_thread_wait_timeout_1_seconds, controller_thread_wait_timeout_1_nanoseconds, &time); + } + else if (count < controller_thread_wait_timeout_2_before) { + controller_time(controller_thread_wait_timeout_2_seconds, controller_thread_wait_timeout_2_nanoseconds, &time); + } + else if (count < controller_thread_wait_timeout_3_before) { + controller_time(controller_thread_wait_timeout_3_seconds, controller_thread_wait_timeout_3_nanoseconds, &time); + } + else { + controller_time(controller_thread_wait_timeout_4_seconds, controller_thread_wait_timeout_4_nanoseconds, &time); + } status = f_thread_condition_wait_timed(&time, &process->wait, &process->wait_lock); @@ -253,6 +266,11 @@ extern "C" { } f_thread_unlock(&process->lock); + + if (count < controller_thread_wait_timeout_3_before) { + count++; + } + } while (status == F_time && main.thread->enabled); return status; diff --git a/level_3/controller/c/private-common.h b/level_3/controller/c/private-common.h index 9b2f91f..74f0011 100644 --- a/level_3/controller/c/private-common.h +++ b/level_3/controller/c/private-common.h @@ -1080,13 +1080,18 @@ extern "C" { #define controller_thread_lock_timeout 100000000 // 0.1 seconds in nanoseconds. #define controller_thread_simulation_timeout 200000 // 0.2 seconds in microseconds. - // @todo implement a staged incrementing wait that waits a short amount of time for say 3 times, then waits a longer amount of time for say 3 times, and then wait a long period of time. - // example: wait 0.02 seconds for 4 times, then - // wait 0.2 seconds for 8 times, then - // wait 2 seconds for 16 times, then - // wait 20 seconds for every time thereafter. - #define controller_thread_wait_timeout_seconds 5 - #define controller_thread_wait_timeout_nanoseconds 0 + #define controller_thread_wait_timeout_1_before 4 + #define controller_thread_wait_timeout_2_before 12 + #define controller_thread_wait_timeout_3_before 28 + + #define controller_thread_wait_timeout_1_seconds 0 + #define controller_thread_wait_timeout_1_nanoseconds 20000000 + #define controller_thread_wait_timeout_2_seconds 0 + #define controller_thread_wait_timeout_2_nanoseconds 200000000 + #define controller_thread_wait_timeout_3_seconds 2 + #define controller_thread_wait_timeout_3_nanoseconds 0 + #define controller_thread_wait_timeout_4_seconds 20 + #define controller_thread_wait_timeout_4_nanoseconds 0 typedef struct { bool enabled; diff --git a/level_3/controller/c/private-thread.c b/level_3/controller/c/private-thread.c index bd273bb..c9bce23 100644 --- a/level_3/controller/c/private-thread.c +++ b/level_3/controller/c/private-thread.c @@ -205,8 +205,6 @@ extern "C" { } } - // @todo consider redesigning to spawn forked processes from main thread to allow proper deallocation via a timed mutex condition (only need to do this for scripts). - // only make the rule and control threads available once any/all pre-processing and are completed. if (F_status_is_error_not(status) && status != F_signal && status != F_child && thread.enabled) { @@ -544,7 +542,7 @@ extern "C" { if (main->data->parameters[controller_parameter_interruptable].result == f_console_result_found) { if (signal == F_signal_interrupt || signal == F_signal_abort || signal == F_signal_quit || signal == F_signal_termination) { - main->thread->signal = signal; // @todo determine if I need signal saved anymore. + main->thread->signal = signal; controller_thread_process_cancel(main); break; -- 1.8.3.1