]> git.sesse.net Git - vlc/blobdiff - src/misc/mtime.c
misc/darwin_specific.c: Fix framework detection code.
[vlc] / src / misc / mtime.c
index 5613483e5824477709f7dbe02c7474f95efb194e..9a6a276760894c5a89330490263b8bb347784fb9 100644 (file)
@@ -31,9 +31,7 @@
 
 #include <vlc/vlc.h>
 
-#include <stdio.h>                                              /* sprintf() */
 #include <time.h>                      /* clock_gettime(), clock_nanosleep() */
-#include <stdlib.h>                                               /* lldiv() */
 #include <assert.h>
 #include <errno.h>
 
@@ -69,6 +67,19 @@ struct timespec
 int nanosleep(struct timespec *, struct timespec *);
 #endif
 
+#ifdef HAVE_CLOCK_NANOSLEEP
+#  if !defined _POSIX_CLOCK_SELECTION || (_POSIX_CLOCK_SELECTION - 0 <= 0)
+/*
+ * We cannot use the monotonic clock is clock selection is not available,
+ * as it would screw vlc_cond_timedwait() completely. Instead, we have to
+ * stick to the realtime clock. Nevermind it screws everything when ntpdate
+ * warps the wall clock.
+ */
+#    undef CLOCK_MONOTONIC
+#    define CLOCK_MONOTONIC CLOCK_REALTIME
+#  endif
+#endif
+
 /**
  * Return a date in a readable format
  *
@@ -129,9 +140,6 @@ static inline unsigned mprec( void )
 
 static unsigned prec = 0;
 static volatile mtime_t cached_time = 0;
-#if (_POSIX_MONOTONIC_CLOCK - 0 < 0)
-# define CLOCK_MONOTONIC CLOCK_REALTIME
-#endif
 
 /**
  * Return high precision date
@@ -290,7 +298,7 @@ void msleep( mtime_t delay )
 {
     mtime_t earlier = cached_time;
 
-#if defined( HAVE_CLOCK_NANOSLEEP ) 
+#if defined( HAVE_CLOCK_NANOSLEEP )
     lldiv_t d = lldiv( delay, 1000000 );
     struct timespec ts = { d.quot, d.rem * 1000 };
 
@@ -430,7 +438,10 @@ mtime_t date_Increment( date_t *p_date, uint32_t i_nb_samples )
     return p_date->date;
 }
 
+#ifndef HAVE_GETTIMEOFDAY
+
 #ifdef WIN32
+
 /*
  * Number of micro-seconds between the beginning of the Windows epoch
  * (Jan. 1, 1601) and the Unix epoch (Jan. 1, 1970).
@@ -467,9 +478,10 @@ static int gettimeofday (struct timeval *tv, void *tz )
     tv->tv_usec = (long) (tim % 1000000L);
     return (0);
 }
-#endif
 
+#endif
 
+#endif
 
 /**
  * @return NTP 64-bits timestamp in host byte order.