- tv_divide(wanted, &diff, &tmp); /* sleep time between two snapshots */
- diff.tv_sec = s->completion_time; /* completion time of the latest snapshot */
- diff.tv_usec = 0;
- tv_add(&diff, &tmp, &next_snapshot_time);
- ret = (tv_diff(&now, &next_snapshot_time, &diff) < 0)? 0 : 1;
+ next_snapshot_time = now;
+ if (num_complete_snapshots == 0)
+ goto out;
+ x /= num_complete_snapshots; /* avg time to create one snapshot */
+ if (unit_interval < x * wanted) /* oops, no sleep at all */
+ goto out;
+ next_snapshot_time = s->completion_time + unit_interval / wanted - x;