Commit 3425b2e6 authored by Sam Hocevar's avatar Sam Hocevar

* ./src/misc/mtime.c: we use nanosleep whenever possible (patch from Meuuh).

parent 815d5642
This diff is collapsed.
...@@ -111,7 +111,7 @@ dnl The -DSYS_FOO flag ...@@ -111,7 +111,7 @@ dnl The -DSYS_FOO flag
save_CFLAGS="${save_CFLAGS} -DSYS_`echo ${SYS} | sed -e 's/-.*//' | tr 'abcdefghijklmnopqrstuvwxyz.' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_'`" save_CFLAGS="${save_CFLAGS} -DSYS_`echo ${SYS} | sed -e 's/-.*//' | tr 'abcdefghijklmnopqrstuvwxyz.' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_'`"
dnl Check for system libs needed dnl Check for system libs needed
AC_CHECK_FUNCS(gettimeofday select strerror strtod strtol isatty usleep vasprintf swab sigrelse getpwuid memalign posix_memalign gethostbyname2) AC_CHECK_FUNCS(gettimeofday select strerror strtod strtol isatty vasprintf swab sigrelse getpwuid memalign posix_memalign gethostbyname2)
AC_CHECK_FUNC(connect,,[ AC_CHECK_FUNC(connect,,[
AC_CHECK_LIB(socket,connect, AC_CHECK_LIB(socket,connect,
...@@ -124,10 +124,12 @@ AC_CHECK_FUNC(gethostbyname,,[ ...@@ -124,10 +124,12 @@ AC_CHECK_FUNC(gethostbyname,,[
AC_CHECK_FUNC(gethostbyname,,[ AC_CHECK_FUNC(gethostbyname,,[
AC_CHECK_LIB(bind,gethostbyname,ipv4_LDFLAGS="${ipv4_LDFLAGS} -lbind") AC_CHECK_LIB(bind,gethostbyname,ipv4_LDFLAGS="${ipv4_LDFLAGS} -lbind")
]) ])
AC_CHECK_FUNC(nanosleep,,[ AC_CHECK_FUNCS(nanosleep,,[
AC_CHECK_LIB(rt,nanosleep,vlc_LDFLAGS="${vlc_LDFLAGS} -lrt",[ AC_CHECK_LIB(rt,nanosleep,
AC_CHECK_LIB(posix4,nanosleep,vlc_LDFLAGS="${vlc_LDFLAGS} -lposix4") [vlc_LDFLAGS="${vlc_LDFLAGS} -lrt"],
]) [AC_CHECK_LIB(posix4,nanosleep,
[vlc_LDFLAGS="${vlc_LDFLAGS} -lposix4"])]
)
]) ])
AC_CHECK_FUNC(inet_aton,,[ AC_CHECK_FUNC(inet_aton,,[
AC_CHECK_LIB(resolv,inet_aton,ipv4_LDFLAGS="${ipv4_LDFLAGS} -lresolv") AC_CHECK_LIB(resolv,inet_aton,ipv4_LDFLAGS="${ipv4_LDFLAGS} -lresolv")
...@@ -193,6 +195,14 @@ AC_CHECK_HEADERS(linux/version.h) ...@@ -193,6 +195,14 @@ AC_CHECK_HEADERS(linux/version.h)
AC_HEADER_TIME AC_HEADER_TIME
dnl Mac OS X and other OSes don't have declaration for nanosleep
dnl This only works with autoconf 2.52
AC_CHECK_DECLS(nanosleep)
dnl Make sure we have timespecs
dnl This only works with autoconf 2.52
AC_CHECK_TYPES(struct timespec)
dnl Check for threads library dnl Check for threads library
AC_CHECK_HEADERS(cthreads.h pthread.h kernel/scheduler.h kernel/OS.h) AC_CHECK_HEADERS(cthreads.h pthread.h kernel/scheduler.h kernel/OS.h)
......
...@@ -41,7 +41,7 @@ ...@@ -41,7 +41,7 @@
/* When creating or destroying threads in blocking mode, delay to poll thread /* When creating or destroying threads in blocking mode, delay to poll thread
* status */ * status */
#define THREAD_SLEEP ((int)(0.010*CLOCK_FREQ)) #define THREAD_SLEEP ((mtime_t)(0.010*CLOCK_FREQ))
/* When a thread waits on a condition in debug mode, delay to wait before /* When a thread waits on a condition in debug mode, delay to wait before
* outputting an error message (in second) */ * outputting an error message (in second) */
...@@ -62,7 +62,7 @@ ...@@ -62,7 +62,7 @@
*****************************************************************************/ *****************************************************************************/
/* Base delay in micro second for interface sleeps */ /* Base delay in micro second for interface sleeps */
#define INTF_IDLE_SLEEP ((int)(0.050*CLOCK_FREQ)) #define INTF_IDLE_SLEEP ((mtime_t)(0.050*CLOCK_FREQ))
/* Step for changing gamma, and minimum and maximum values */ /* Step for changing gamma, and minimum and maximum values */
#define INTF_GAMMA_STEP .1 #define INTF_GAMMA_STEP .1
...@@ -73,7 +73,7 @@ ...@@ -73,7 +73,7 @@
*****************************************************************************/ *****************************************************************************/
/* XXX?? */ /* XXX?? */
#define INPUT_IDLE_SLEEP ((int)(0.100*CLOCK_FREQ)) #define INPUT_IDLE_SLEEP ((mtime_t)(0.100*CLOCK_FREQ))
/* /*
* General limitations * General limitations
...@@ -204,13 +204,13 @@ ...@@ -204,13 +204,13 @@
#define VOUT_FPS_SAMPLES 20 #define VOUT_FPS_SAMPLES 20
/* Better be in advance when awakening than late... */ /* Better be in advance when awakening than late... */
#define VOUT_MWAIT_TOLERANCE ((int)(0.020*CLOCK_FREQ)) #define VOUT_MWAIT_TOLERANCE ((mtime_t)(0.020*CLOCK_FREQ))
/* Time to sleep when waiting for a buffer (from vout or the video fifo). /* Time to sleep when waiting for a buffer (from vout or the video fifo).
* It should be approximately the time needed to perform a complete picture * It should be approximately the time needed to perform a complete picture
* loop. Since it only happens when the video heap is full, it does not need * loop. Since it only happens when the video heap is full, it does not need
* to be too low, even if it blocks the decoder. */ * to be too low, even if it blocks the decoder. */
#define VOUT_OUTMEM_SLEEP ((int)(0.020*CLOCK_FREQ)) #define VOUT_OUTMEM_SLEEP ((mtime_t)(0.020*CLOCK_FREQ))
/* The default video output window title */ /* The default video output window title */
#define VOUT_TITLE "VideoLAN Client " VERSION #define VOUT_TITLE "VideoLAN Client " VERSION
...@@ -219,7 +219,7 @@ ...@@ -219,7 +219,7 @@
* Video parser configuration * Video parser configuration
*****************************************************************************/ *****************************************************************************/
#define VPAR_IDLE_SLEEP ((int)(0.010*CLOCK_FREQ)) #define VPAR_IDLE_SLEEP ((mtime_t)(0.010*CLOCK_FREQ))
/* Optimization level, from 0 to 2 - 1 is generally a good compromise. Remember /* Optimization level, from 0 to 2 - 1 is generally a good compromise. Remember
* that raising this level dramatically lengthens the compilation time. */ * that raising this level dramatically lengthens the compilation time. */
...@@ -236,7 +236,7 @@ ...@@ -236,7 +236,7 @@
* Video decoder configuration * Video decoder configuration
*****************************************************************************/ *****************************************************************************/
#define VDEC_IDLE_SLEEP ((int)(0.100*CLOCK_FREQ)) #define VDEC_IDLE_SLEEP ((mtime_t)(0.100*CLOCK_FREQ))
/* Maximum range of values out of the IDCT + motion compensation. */ /* Maximum range of values out of the IDCT + motion compensation. */
#define VDEC_CROPRANGE 2048 #define VDEC_CROPRANGE 2048
......
This diff is collapsed.
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* Functions are prototyped in mtime.h. * Functions are prototyped in mtime.h.
***************************************************************************** *****************************************************************************
* Copyright (C) 1998-2001 VideoLAN * Copyright (C) 1998-2001 VideoLAN
* $Id: mtime.c,v 1.29 2002/05/17 15:14:47 lool Exp $ * $Id: mtime.c,v 1.30 2002/05/17 16:38:41 sam Exp $
* *
* Authors: Vincent Seguin <seguin@via.ecp.fr> * Authors: Vincent Seguin <seguin@via.ecp.fr>
* *
...@@ -52,6 +52,18 @@ ...@@ -52,6 +52,18 @@
# include <sys/time.h> # include <sys/time.h>
#endif #endif
#if defined(HAVE_NANOSLEEP) && !defined(HAVE_STRUCT_TIMESPEC)
struct timespec
{
time_t tv_sec;
long tv_sec;
};
#endif
#if defined(HAVE_NANOSLEEP) && !defined(HAVE_DECL_NANOSLEEP)
int nanosleep(struct timespec *, struct timespec *);
#endif
/***************************************************************************** /*****************************************************************************
* mstrtime: return a date in a readable format * mstrtime: return a date in a readable format
***************************************************************************** *****************************************************************************
...@@ -141,7 +153,7 @@ void mwait( mtime_t date ) ...@@ -141,7 +153,7 @@ void mwait( mtime_t date )
#else #else
struct timeval tv_date, tv_delay; struct timeval tv_date;
mtime_t delay; /* delay in msec, signed to detect errors */ mtime_t delay; /* delay in msec, signed to detect errors */
/* see mdate() about gettimeofday() possible errors */ /* see mdate() about gettimeofday() possible errors */
...@@ -166,10 +178,22 @@ void mwait( mtime_t date ) ...@@ -166,10 +178,22 @@ void mwait( mtime_t date )
st_usleep( delay ); st_usleep( delay );
# else # else
tv_delay.tv_sec = delay / 1000000;
tv_delay.tv_usec = delay % 1000000; # if defined( HAVE_NANOSLEEP )
{
struct timespec ts_delay;
ts_delay.tv_sec = delay / 1000000;
ts_delay.tv_nsec = (delay % 1000000) * 1000;
nanosleep( &ts_delay, NULL );
}
# else
tv_date.tv_sec = delay / 1000000;
tv_date.tv_usec = delay % 1000000;
/* see msleep() about select() errors */ /* see msleep() about select() errors */
select( 0, NULL, NULL, NULL, &tv_delay ); select( 0, NULL, NULL, NULL, &tv_date );
# endif
# endif # endif
...@@ -195,15 +219,24 @@ void msleep( mtime_t delay ) ...@@ -195,15 +219,24 @@ void msleep( mtime_t delay )
#elif defined( WIN32 ) #elif defined( WIN32 )
Sleep( (int) (delay / 1000) ); Sleep( (int) (delay / 1000) );
#elif defined( HAVE_NANOSLEEP )
struct timespec ts_delay;
ts_delay.tv_sec = delay / 1000000;
ts_delay.tv_nsec = (delay % 1000000) * 1000;
nanosleep( &ts_delay, NULL );
#else #else
struct timeval tv_delay; struct timeval tv_delay;
tv_delay.tv_sec = delay / 1000000; tv_delay.tv_sec = delay / 1000000;
tv_delay.tv_usec = delay % 1000000; tv_delay.tv_usec = delay % 1000000;
/* select() return value should be tested, since several possible errors /* select() return value should be tested, since several possible errors
* can occur. However, they should only happen in very particular occasions * can occur. However, they should only happen in very particular occasions
* (i.e. when a signal is sent to the thread, or when memory is full), and * (i.e. when a signal is sent to the thread, or when memory is full), and
* can be ingnored. */ * can be ignored. */
select( 0, NULL, NULL, NULL, &tv_delay ); select( 0, NULL, NULL, NULL, &tv_delay );
#endif #endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment