- clock_gettime(CLOCK_MONOTONIC, &time_end);
- dbg("End time: s: %ld, ns: %ld", time_end.tv_sec, time_end.tv_nsec);
- timespecsub(&time_end, &time_start, &elapsed);
- dbg("Elapsed s: %ld ns: %ld", elapsed.tv_sec, elapsed.tv_nsec);
- if (elapsed.tv_sec == 0 && elapsed.tv_nsec < NSEC_PER_SEC / FPS) {
- /* remaining delay, _relative_ to time_end */
- remaining.tv_nsec = (NSEC_PER_SEC / FPS) - elapsed.tv_nsec;
- dbg("Sleeping for: ns: %ld", remaining.tv_nsec);
- clock_nanosleep(CLOCK_MONOTONIC, 0, &remaining, NULL);
- }