Skip to content

Commit

Permalink
Changed to use nanosleep
Browse files Browse the repository at this point in the history
  • Loading branch information
zsolt-donca committed Jan 10, 2021
1 parent eb62b8e commit 2d7833c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
6 changes: 6 additions & 0 deletions include/time-util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) +
Expand Down
1 change: 0 additions & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
5 changes: 4 additions & 1 deletion src/screencast/fps_limit.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 2d7833c

Please sign in to comment.