make refreshs align with minutes

This commit is contained in:
Gereon Kremer 2013-01-05 12:47:02 +01:00 committed by Michael Stapelberg
parent 6147e2b268
commit 11757b8105

View File

@ -515,10 +515,11 @@ int main(int argc, char *argv[]) {
/* To provide updates on every full second (as good as possible)
* we dont use sleep(interval) but we sleep until the next
* second (with microsecond precision) plus (interval-1)
* seconds. */
* seconds. We also align to 60 seconds modulo interval such
* that we start with :00 on every new minute. */
struct timeval current_timeval;
gettimeofday(&current_timeval, NULL);
struct timespec ts = {interval - 1, (10e5 - current_timeval.tv_usec) * 1000};
struct timespec ts = {interval - 1 - (current_timeval.tv_sec % interval), (10e5 - current_timeval.tv_usec) * 1000};
nanosleep(&ts, NULL);
}
}