comp_compositor: use nanosleep instead of usleep

Improves portability
This commit is contained in:
Drew DeVault 2019-09-24 09:43:21 -04:00 committed by Jakob Bornecrantz
parent 9c7c818637
commit c6586cfd1e
2 changed files with 48 additions and 3 deletions

View file

@ -0,0 +1,43 @@
// Copyright 2019, Collabora, Ltd.
// SPDX-License-Identifier: BSL-1.0
/*!
* @file
* @brief Wrapper around OS native time functions.
* @author Drew DeVault <sir@cmpwn.com>
*
* @ingroup aux_os
*/
#pragma once
#include "xrt/xrt_config.h"
#include "xrt/xrt_compiler.h"
#ifdef XRT_OS_LINUX
#include <time.h>
#else
#error "No time support on non-Linux platforms yet."
#endif
#ifdef __cplusplus
extern "C" {
#endif
/*!
* Write an output report to the given device.
*/
XRT_MAYBE_UNUSED static inline void
os_nanosleep(long nsec)
{
#ifdef XRT_OS_LINUX
struct timespec spec = {
.tv_sec = 0,
.tv_nsec = nsec,
};
nanosleep(&spec, NULL);
#endif
}
#ifdef __cplusplus
}
#endif

View file

@ -13,6 +13,8 @@
#include <stdarg.h>
#include <string.h>
#include "os/os_time.h"
#include "util/u_debug.h"
#include "util/u_misc.h"
#include "util/u_time.h"
@ -90,11 +92,11 @@ compositor_wait_frame(struct xrt_compositor *xc,
// This needs improvement, but blocks for plausible timings.
int64_t now_ns = time_state_get_now(c->timekeeping);
int64_t already_used_ns = now_ns - c->last_frame_time_ns;
int64_t remaining_usec = (interval_ns - already_used_ns) / 1000;
int64_t remaining_nsec = interval_ns - already_used_ns;
// leave 1.25 ms for overhead
if (remaining_usec > 1250) {
usleep(remaining_usec - 1250);
if (remaining_nsec > 1250000) {
os_nanosleep(remaining_nsec - 1250000);
}
*predicted_display_period = interval_ns;