- xtime_t now = gethrxtime ();
- double increment = XTIME_PRECISION * seconds;
- xtime_t incr = increment;
- stop = now + incr + (incr < increment);
- overflow = (stop < now);
- }
-
- /* Separate whole seconds from nanoseconds.
- Be careful to detect any overflow. */
- ts_sleep.tv_sec = seconds;
- ns = BILLION * (seconds - ts_sleep.tv_sec);
- overflow |= ! (ts_sleep.tv_sec <= seconds && 0 <= ns && ns <= BILLION);
- ts_sleep.tv_nsec = ns;
-
- /* Round up to the next whole number, if necessary, so that we
- always sleep for at least the requested amount of time. Assuming
- the default rounding mode, we don't have to worry about the
- rounding error when computing 'ns' above, since the error won't
- cause 'ns' to drop below an integer boundary. */
- ts_sleep.tv_nsec += (ts_sleep.tv_nsec < ns);
-
- /* Normalize the interval length. nanosleep requires this. */
- if (BILLION <= ts_sleep.tv_nsec)
- {
- time_t t = ts_sleep.tv_sec + 1;
-
- /* Detect integer overflow. */
- overflow |= (t < ts_sleep.tv_sec);
-
- ts_sleep.tv_sec = t;
- ts_sleep.tv_nsec -= BILLION;
+ time_t floor_seconds = seconds;
+ double ns = BILLION * (seconds - floor_seconds);
+ ts_sleep.tv_sec = floor_seconds;
+
+ /* Round up to the next whole number, if necessary, so that we
+ always sleep for at least the requested amount of time. Assuming
+ the default rounding mode, we don't have to worry about the
+ rounding error when computing 'ns' above, since the error won't
+ cause 'ns' to drop below an integer boundary. */
+ ts_sleep.tv_nsec = ns;
+ ts_sleep.tv_nsec += (ts_sleep.tv_nsec < ns);
+
+ /* Normalize the interval length. nanosleep requires this. */
+ if (BILLION <= ts_sleep.tv_nsec)
+ {
+ if (ts_sleep.tv_sec == TIME_T_MAX)
+ overflow = true;
+ else
+ {
+ ts_sleep.tv_sec++;
+ ts_sleep.tv_nsec -= BILLION;
+ }
+ }