# include <sys/time.h>
#endif
+#ifdef __APPLE__
+# include <mach/mach.h>
+# include <mach/mach_time.h>
+#endif
+
#if !defined(HAVE_STRUCT_TIMESPEC)
struct timespec
{
#endif
}
+#ifdef __APPLE__
+static mach_timebase_info_data_t mtime_timebase_info;
+static pthread_once_t mtime_timebase_info_once = PTHREAD_ONCE_INIT;
+static void mtime_init_timebase(void)
+{
+ mach_timebase_info(&mtime_timebase_info);
+}
+#endif
+
/**
* Return high precision date
*
#elif defined( HAVE_KERNEL_OS_H )
res = real_time_clock_usecs();
+#elif defined( __APPLE__ )
+ pthread_once(&mtime_timebase_info_once, mtime_init_timebase);
+ uint64_t date = mach_absolute_time();
+
+ /* Convert to nanoseconds */
+ date *= mtime_timebase_info.numer;
+ date /= mtime_timebase_info.denom;
+
+ /* Convert to microseconds */
+ res = date / 1000;
#elif defined( WIN32 ) || defined( UNDER_CE )
/* We don't need the real date, just the value of a high precision timer */
static mtime_t freq = INT64_C(-1);
i_previous_time = res;
LeaveCriticalSection( &date_lock );
}
+#elif defined( __APPLE__ ) /* The version that should be used, if it was cancelable */
+ pthread_once(&mtime_timebase_info_once, mtime_init_timebase);
+ uint64_t mach_time = date * 1000 * mtime_timebase_info.denom / mtime_timebase_info.numer;
+ mach_wait_until(mach_time);
+
#else
struct timeval tv_date;
while( nanosleep( &ts_delay, &ts_delay ) && ( errno == EINTR ) );
+#elif defined( __APPLE__ ) /* The version that should be used, if it was cancelable */
+ pthread_once(&mtime_timebase_info_once, mtime_init_timebase);
+ uint64_t mach_time = delay * 1000 * mtime_timebase_info.denom / mtime_timebase_info.numer;
+ mach_wait_until(mach_time + mach_absolute_time());
+
#else
struct timeval tv_delay;
# include <execinfo.h>
#endif
+#ifdef __APPLE__
+# include <sys/time.h> /* gettimeofday in vlc_cond_timedwait */
+#endif
+
/**
* Print a backtrace to the standard error for debugging purpose.
*/
mtime_t deadline)
{
#if defined(LIBVLC_USE_PTHREAD)
+#ifdef __APPLE__
+ /* mdate() is mac_absolute_time on osx, which we must convert to do
+ * the same base than gettimeofday() on which pthread_cond_timedwait
+ * counts on. */
+ mtime_t oldbase = mdate();
+ struct timeval tv;
+ gettimeofday(&tv, NULL);
+ mtime_t newbase = (mtime_t)tv.tv_sec * 1000000 + (mtime_t) tv.tv_usec;
+ deadline = deadline - oldbase + newbase;
+#endif
lldiv_t d = lldiv( deadline, CLOCK_FREQ );
struct timespec ts = { d.quot, d.rem * (1000000000 / CLOCK_FREQ) };