+static void
+sleep_from (struct timeval *now, struct timeval *then, long usecs_per_step)
+{
+ /* If several seconds have passed, the machine must have been asleep
+ or thrashing or something. Don't sleep in that case, to avoid
+ overflowing and sleeping for an unconscionably long time. This
+ function should only be sleeping for very short periods.
+ */
+ if (now->tv_sec - then->tv_sec < 5)
+ {
+ long diff = (((now->tv_sec - then->tv_sec) * 1000000) +
+ now->tv_usec - then->tv_usec);
+ if (usecs_per_step > diff)
+ usleep (usecs_per_step - diff);
+ }
+
+ then->tv_sec = now->tv_sec;
+ then->tv_usec = now->tv_usec;
+}
+
+
+