From d3d3a32c9d389cc0d6a91b389988a225ae01c948 Mon Sep 17 00:00:00 2001 From: Mans Rullgard Date: Thu, 21 Jun 2012 17:00:25 +0100 Subject: lavu: add av_usleep() function This function implements a delay using the first available of the following functions: - nanosleep() - usleep() - Sleep() (Windows) The conditional #includes in time.c are simplified by including unistd.h and windows.h whenever they are available rather than having these lines triggered by specific functions. Signed-off-by: Mans Rullgard --- libavutil/time.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'libavutil/time.c') diff --git a/libavutil/time.c b/libavutil/time.c index 80c4029d9b..51779c5d17 100644 --- a/libavutil/time.c +++ b/libavutil/time.c @@ -20,13 +20,19 @@ #include #include +#include #if HAVE_GETTIMEOFDAY #include -#elif HAVE_GETSYSTEMTIMEASFILETIME +#endif +#if HAVE_UNISTD_H +#include +#endif +#if HAVE_WINDOWS_H #include #endif #include "libavutil/time.h" +#include "error.h" int64_t av_gettime(void) { @@ -44,3 +50,19 @@ int64_t av_gettime(void) return -1; #endif } + +int av_usleep(unsigned usec) +{ +#if HAVE_NANOSLEEP + struct timespec ts = { usec / 1000000, usec % 1000000 * 1000 }; + while (nanosleep(&ts, &ts) < 0 && errno == EINTR); + return 0; +#elif HAVE_USLEEP + return usleep(usec); +#elif HAVE_SLEEP + Sleep(usec / 1000); + return 0; +#else + return AVERROR(ENOSYS); +#endif +} -- cgit v1.2.3