* 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
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);
}
f_thread_unlock(&process->lock);
+
+ if (count < controller_thread_wait_timeout_3_before) {
+ count++;
+ }
+
} while (status == F_time && main.thread->enabled);
return status;
#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;
}
}
- // @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) {
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;