From df0cb344c487f0ccd229ec21093a0fb852d49f12 Mon Sep 17 00:00:00 2001 From: =?utf8?q?R=C3=A9mi=20Denis-Courmont?= Date: Sat, 27 May 2006 17:40:15 +0000 Subject: [PATCH] src/misc/mtime.c: - Don't use TIMER_ABSTIME which sucks (at least on Linux with HZ=1000) - Cosmetic configure.ac: - Check for clock_nanosleep() rather than clock_gettime(), as it is more recent and we need both. --- configure.ac | 4 ++-- src/misc/mtime.c | 20 ++++++++++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/configure.ac b/configure.ac index 96d09dc43a..b17892c09a 100644 --- a/configure.ac +++ b/configure.ac @@ -720,9 +720,9 @@ VLC_ADD_LDFLAGS([vlc plugin],[${THREAD_LIB}]) dnl Don't link with rt when using GNU-pth if test "${THREAD_LIB}" != "-lpth" && test "${THREAD_LIB}" != "-lst"; then - AC_CHECK_LIB(rt, clock_gettime, [ + AC_CHECK_LIB(rt, clock_nanosleep, [ VLC_ADD_LDFLAGS([vlc],[-lrt]) - AC_DEFINE(HAVE_CLOCK_GETTIME, 1, [Define to 1 if you have clock_gettime.]) + AC_DEFINE(HAVE_CLOCK_NANOSLEEP, 1, [Define to 1 if you have clock_nanosleep.]) ], [ dnl HP/UX port AC_CHECK_LIB(rt,sem_init, [VLC_ADD_LDFLAGS([vlc],[-lrt])]) diff --git a/src/misc/mtime.c b/src/misc/mtime.c index b80d19b4b2..c8431e1cbe 100644 --- a/src/misc/mtime.c +++ b/src/misc/mtime.c @@ -187,7 +187,7 @@ mtime_t mdate( void ) return usec_time; } -#elif defined (HAVE_CLOCK_GETTIME) +#elif defined (HAVE_CLOCK_NANOSLEEP) struct timespec ts; # if (_POSIX_MONOTONIC_CLOCK - 0 >= 0) @@ -239,14 +239,21 @@ void mwait( mtime_t date ) } msleep( delay ); -#elif defined (HAVE_CLOCK_GETTIME) +#elif defined (HAVE_CLOCK_NANOSLEEP) +# if defined (HAVE_TIMER_ABSTIME_THAT_ACTUALLY_WORKS_WELL) lldiv_t d = lldiv( date, 1000000 ); struct timespec ts = { d.quot, d.rem }; -# if (_POSIX_MONOTONIC_CLOCK - 0 >= 0) +# if (_POSIX_MONOTONIC_CLOCK - 0 >= 0) if( clock_nanosleep( CLOCK_MONOTONIC, TIMER_ABSTIME, &ts, NULL ) ) -# endif +# endif clock_nanosleep( CLOCK_REALTIME, TIMER_ABSTIME, &ts, NULL ); +# else + date -= mdate (); + if( date <= 0) + return; + msleep( date ); +# endif #else struct timeval tv_date; @@ -316,11 +323,12 @@ void msleep( mtime_t delay ) #elif defined( WIN32 ) || defined( UNDER_CE ) Sleep( (int) (delay / 1000) ); -#elif defined( HAVE_CLOCK_GETTIME ) +#elif defined( HAVE_CLOCK_NANOSLEEP ) lldiv_t d = lldiv( delay, 1000000 ); struct timespec ts = { d.quot, d.rem * 1000 }; + # if (_POSIX_CLOCK_MONOTONIC - 0 >= 0) - if (clock_nanosleep( CLOCK_MONOTONIC, 0, &ts, NULL ) ) + if( clock_nanosleep( CLOCK_MONOTONIC, 0, &ts, NULL ) ) # endif clock_nanosleep( CLOCK_REALTIME, 0, &ts, NULL ); -- 2.39.2