diff options
author | Vito Caputo <vcaputo@pengaru.com> | 2020-07-12 11:14:30 -0700 |
---|---|---|
committer | Vito Caputo <vcaputo@pengaru.com> | 2020-07-12 11:14:30 -0700 |
commit | 193a1e77bf798ef2ce2a1546d845f3bfe6ab3928 (patch) | |
tree | 5bc2701279b1fd3fdd4d3054270d7a003e23e708 /src/rmd_timer.c | |
parent | 99bc91a3c939e07f2d754a67dce60a55d509b3c1 (diff) |
*: standardize sleeps on nanosleep()
usleep() is deprecated by posix in favor of nanosleep(), nanosleep
doesn't dick with signals so it's generally better anyways.
Diffstat (limited to 'src/rmd_timer.c')
-rw-r--r-- | src/rmd_timer.c | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/src/rmd_timer.c b/src/rmd_timer.c index b8161ca..6c3e483 100644 --- a/src/rmd_timer.c +++ b/src/rmd_timer.c @@ -34,12 +34,15 @@ #include <stdio.h> #include <stdlib.h> #include <errno.h> +#include <time.h> #include <unistd.h> void *rmdTimer(ProgData *pdata){ - long unsigned int secs_tw=1/pdata->args.fps; - long unsigned int usecs_tw=(1000000)/pdata->args.fps- secs_tw*1000000; + struct timespec delay; + + delay.tv_sec = 1.f / pdata->args.fps; + delay.tv_nsec = 1000000000.f / pdata->args.fps - delay.tv_sec * 1000000000.f; while (pdata->timer_alive) { @@ -70,11 +73,7 @@ void *rmdTimer(ProgData *pdata){ pthread_mutex_unlock(&pdata->time_mutex); pthread_cond_signal(&pdata->time_cond); - /* FIXME use nanosleep */ - if (secs_tw) - sleep(secs_tw); - - usleep(usecs_tw); + nanosleep(&delay, NULL); } pthread_exit(&errno); |