X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=include%2Fvlc_mtime.h;h=f3bb895d42fdbde9294c2c60d378f5889ddaf684;hb=584fb9f5d0a4342a4651f935f2dd96870caa09ad;hp=458cf35d35ada05935dd81441f937af8fd91adbc;hpb=d3fe7f28797d4dba65ffcdd60bf932e758a48a9e;p=vlc diff --git a/include/vlc_mtime.h b/include/vlc_mtime.h index 458cf35d35..f3bb895d42 100644 --- a/include/vlc_mtime.h +++ b/include/vlc_mtime.h @@ -1,5 +1,6 @@ /***************************************************************************** - * mtime.h: high resolution time management functions + * vlc_mtime.h: high resolution time management functions + ***************************************************************************** * This header provides portable high precision time management functions, * which should be the only ones used in other segments of the program, since * functions like gettimeofday() and ftime() are not always supported. @@ -28,6 +29,9 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ +#ifndef __VLC_MTIME_H +# define __VLC_MTIME_H 1 + /***************************************************************************** * LAST_MDATE: date which will never happen ***************************************************************************** @@ -64,6 +68,57 @@ VLC_EXPORT( void, mwait, ( mtime_t date ) ); VLC_EXPORT( void, msleep, ( mtime_t delay ) ); VLC_EXPORT( char *, secstotimestr, ( char *psz_buffer, int secs ) ); +#if defined (__GNUC__) && defined (__linux__) +# define VLC_HARD_MIN_SLEEP 1000 /* Linux has 100, 250, 300 or 1000Hz */ +# define VLC_SOFT_MIN_SLEEP 9000000 + +static +__attribute__((unused)) +__attribute__((noinline)) +__attribute__((error("sorry, cannot sleep for such short a time"))) +mtime_t impossible_delay( mtime_t delay ) +{ + (void) delay; + return VLC_HARD_MIN_SLEEP; +} + +static +__attribute__((unused)) +__attribute__((noinline)) +__attribute__((warning("use proper event handling instead of short delay"))) +mtime_t harmful_delay( mtime_t delay ) +{ + return delay; +} + +# define check_delay( d ) \ + ((__builtin_constant_p(d < VLC_HARD_MIN_SLEEP) \ + && (d < VLC_HARD_MIN_SLEEP)) \ + ? impossible_delay(d) \ + : ((__builtin_constant_p(d < VLC_SOFT_MIN_SLEEP) \ + && (d < VLC_SOFT_MIN_SLEEP)) \ + ? harmful_delay(d) \ + : d)) + +static +__attribute__((unused)) +__attribute__((noinline)) +__attribute__((error("deadlines can not be constant"))) +mtime_t impossible_deadline( mtime_t deadline ) +{ + return deadline; +} + +# define check_deadline( d ) \ + (__builtin_constant_p(d) ? impossible_deadline(d) : d) +#else +# define check_delay(d) (d) +# define check_deadline(d) (d) +#endif + +#define msleep(d) msleep(check_delay(d)) +#define mwait(d) mwait(check_deadline(d)) + /***************************************************************************** * date_t: date incrementation without long-term rounding errors *****************************************************************************/ @@ -81,3 +136,5 @@ VLC_EXPORT( void, date_Set, ( date_t *, mtime_t ) ); VLC_EXPORT( mtime_t, date_Get, ( const date_t * ) ); VLC_EXPORT( void, date_Move, ( date_t *, mtime_t ) ); VLC_EXPORT( mtime_t, date_Increment, ( date_t *, uint32_t ) ); +VLC_EXPORT( uint64_t, NTPtime64, ( void ) ); +#endif /* !__VLC_MTIME_ */