TIMER: Fix sim_idle_ms_sleep() return value to be more precise

delta time computation converting the difference between two timespec
structures values to milliseconds previously truncated the difference which,
depending on the value of when the starting value in the delta happened,
along with when an OS clock tick occurred, may have resulted in a small
delta and an apparent sleep time of 0.  A more accurate result is produced
when the conversion from nanoseconds to milliseconds is rounded up
before the usecs/nsecs are truncated.
This commit is contained in:
Mark Pizzolato 2020-04-28 07:10:57 -07:00
parent 4313f9fe3c
commit 7ebd22edaa

View file

@ -312,7 +312,7 @@ if (!timedout) {
AIO_UPDATE_QUEUE; AIO_UPDATE_QUEUE;
} }
sim_timespec_diff (&delta_time, &done_time, &start_time); sim_timespec_diff (&delta_time, &done_time, &start_time);
delta_ms = (uint32)((delta_time.tv_sec * 1000) + (delta_time.tv_nsec / 1000000)); delta_ms = (uint32)((delta_time.tv_sec * 1000) + ((delta_time.tv_nsec + 500000) / 1000000));
return delta_ms; return delta_ms;
} }
#else #else