From 2d7833cfc9646c7f41759f6339b995643faa8ddb Mon Sep 17 00:00:00 2001 From: Zsolt Donca Date: Sun, 10 Jan 2021 19:51:05 +0200 Subject: [PATCH] Changed to use nanosleep --- include/time-util.h | 6 ++++++ meson.build | 1 - src/screencast/fps_limit.c | 5 ++++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/include/time-util.h b/include/time-util.h index 9f9fa2b8..8c67100f 100644 --- a/include/time-util.h +++ b/include/time-util.h @@ -25,6 +25,12 @@ static inline uint64_t timespec_to_us(const struct timespec* ts) (uint64_t)ts->tv_nsec / UINT64_C(1000); } +static inline void us_to_timespec(uint64_t time_us, struct timespec* ts) +{ + ts->tv_sec = time_us / UINT64_C(1000000); + ts->tv_nsec = time_us % UINT64_C(1000000) * UINT64_C(1000); +} + static inline uint64_t timespec_to_ms(const struct timespec* ts) { return (uint64_t)ts->tv_sec * UINT64_C(1000) + diff --git a/meson.build b/meson.build index 8ff9940e..39188a06 100644 --- a/meson.build +++ b/meson.build @@ -18,7 +18,6 @@ add_project_arguments(cc.get_supported_arguments([ '-Wno-missing-field-initializers', '-Wno-unused-parameter', '-D_POSIX_C_SOURCE=200809L', - '-D_GNU_SOURCE', ]), language: 'c') inc = include_directories('include') diff --git a/src/screencast/fps_limit.c b/src/screencast/fps_limit.c index f865af62..92feb53c 100644 --- a/src/screencast/fps_limit.c +++ b/src/screencast/fps_limit.c @@ -26,7 +26,10 @@ void fps_limit_apply(struct fps_limit_state* state, double max_fps) { int64_t delay_us = target_us - elapsed_us; if (delay_us > 0) { logprint(TRACE, "fps_limit: elapsed time since the end of last sleep: %u, sleeping for %u (microseconds)", elapsed_us, delay_us); - usleep(delay_us); + + struct timespec delay; + us_to_timespec(delay_us, &delay); + nanosleep(&delay, NULL); } state->last_time_us = gettime_us();