From: Kevin Day Date: Sun, 31 Oct 2021 04:00:42 +0000 (-0500) Subject: Regression: controller_time_micro() is waiting too long. X-Git-Tag: 0.5.7~103 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=7b431bb4fbb6f0e239024e5e734d1883956efc90;p=fll Regression: controller_time_micro() is waiting too long. Turns out that my calculation is in milliseconds but the value is not in milliseconds (it says microseconds!). Change this to milliseconds and update the time as appropriate. --- diff --git a/level_3/controller/c/private-common.c b/level_3/controller/c/private-common.c index 7d0c4e3..b5b13d8 100644 --- a/level_3/controller/c/private-common.c +++ b/level_3/controller/c/private-common.c @@ -923,16 +923,16 @@ extern "C" { } #endif // _di_controller_time_ -#ifndef _di_controller_time_micro_ - struct timespec controller_time_micro(const f_number_unsigned_t microseconds) { +#ifndef _di_controller_time_milliseconds_ + struct timespec controller_time_milliseconds(const f_number_unsigned_t milliseconds) { struct timespec time; - time.tv_sec = microseconds / 1000; - time.tv_nsec = (time.tv_sec ? microseconds - time.tv_sec : microseconds) * 1000; + time.tv_sec = milliseconds > 1000 ? milliseconds / 1000 : 0; + time.tv_nsec = (time.tv_sec ? milliseconds - time.tv_sec : milliseconds) * 1000; return time; } -#endif // _di_controller_time_micro_ +#endif // _di_controller_time_milliseconds_ #ifdef __cplusplus } // extern "C" diff --git a/level_3/controller/c/private-common.h b/level_3/controller/c/private-common.h index cbb6cbe..0ed001a 100644 --- a/level_3/controller/c/private-common.h +++ b/level_3/controller/c/private-common.h @@ -1531,7 +1531,7 @@ extern "C" { #define controller_thread_cleanup_interval_short_d 180 // 3 minutes in seconds. #define controller_thread_exit_process_cancel_wait_d 600000000 // 0.6 seconds in nanoseconds. #define controller_thread_exit_process_cancel_total_d 150 // 90 seconds in multiples of wait. - #define controller_thread_simulation_timeout_d 200000 // 0.2 seconds in microseconds. + #define controller_thread_simulation_timeout_d 200 // 0.2 seconds in milliseconds. #define controller_thread_signal_wait_timeout_seconds_d 70 #define controller_thread_signal_wait_timeout_nanoseconds_d 0 @@ -2470,17 +2470,17 @@ extern "C" { #endif // _di_controller_time_ /** - * Convert microseconds to nanoseconds. + * Convert milliseconds to nanoseconds. * - * @param microseconds - * The number of microseconds. + * @param milliseconds + * The number of milliseconds. * * @return * A time structure suitable for passing to nanosleep() and similar functions. */ -#ifndef _di_controller_time_micro_ - extern struct timespec controller_time_micro(const f_number_unsigned_t microseconds) F_attribute_visibility_internal_d; -#endif // _di_controller_time_micro_ +#ifndef _di_controller_time_milliseconds_ + extern struct timespec controller_time_milliseconds(const f_number_unsigned_t milliseconds) F_attribute_visibility_internal_d; +#endif // _di_controller_time_milliseconds_ #ifdef __cplusplus } // extern "C" diff --git a/level_3/controller/c/private-rule.c b/level_3/controller/c/private-rule.c index 12ffec7..89fccb6 100644 --- a/level_3/controller/c/private-rule.c +++ b/level_3/controller/c/private-rule.c @@ -1645,7 +1645,8 @@ extern "C" { // sleep for less than a second to better show simulation of synchronous vs asynchronous. { - struct timespec delay = controller_time_micro(controller_thread_simulation_timeout_d); + struct timespec delay = controller_time_milliseconds(controller_thread_simulation_timeout_d); + nanosleep(&delay, 0); } @@ -1896,7 +1897,8 @@ extern "C" { // sleep for less than a second to better show simulation of synchronous vs asynchronous. { - struct timespec delay = controller_time_micro(controller_thread_simulation_timeout_d); + struct timespec delay = controller_time_milliseconds(controller_thread_simulation_timeout_d); + nanosleep(&delay, 0); } @@ -2080,7 +2082,7 @@ extern "C" { } if (rerun_item->delay) { - struct timespec time = controller_time_micro(rerun_item->delay); + struct timespec time = controller_time_milliseconds(rerun_item->delay); if (nanosleep(&time, 0) < 0) { return -1;