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.
}
#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"
#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
#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"
// 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);
}
// 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);
}
}
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;