# include <mmsystem.h>
#endif
-#if defined( UNDER_CE )
-# include <windows.h>
-#endif
-
#if defined(HAVE_SYS_TIME_H)
# include <sys/time.h>
#endif
return res;
}
+#undef mwait
/**
* Wait for a date
*
}
vlc_testcancel();
+#elif defined( __APPLE__ )
+ /* Explicit hack: OSX does not cancel at nanosleep() */
+ vlc_mutex_t lock;
+ vlc_cond_t wait;
+
+ vlc_mutex_init (&lock);
+ vlc_cond_init (&wait);
+ vlc_mutex_lock (&lock);
+
+ vlc_cleanup_push (vlc_mutex_destroy, &lock);
+ vlc_cleanup_push (vlc_cond_destroy, &wait);
+ vlc_cleanup_push (vlc_mutex_unlock, &lock);
+
+ vlc_cond_timedwait (&wait, &lock, date);
+
+ vlc_cleanup_run ();
+ vlc_cleanup_run ();
+ vlc_cleanup_run ();
+
#else
mtime_t delay = date - mdate();
if( delay > 0 )
#include "libvlc.h" /* vlc_backtrace() */
#undef msleep
+#if defined(__APPLE__) && defined( HAVE_NANOSLEEP )
+/* Mac OS X 10.5's nanosleep is not a cancellation point */
+static inline int
+semi_testcancelable_nanosleep(const struct timespec *rqtp, struct timespec *rmtp)
+{
+ int ret;
+ pthread_testcancel();
+ ret = nanosleep(rqtp, rmtp);
+ pthread_testcancel();
+ return ret;
+}
+#define nanosleep semi_testcancelable_nanosleep
+#endif
+
/**
* Portable usleep(). Cancellation point.
*
*/
void msleep( mtime_t delay )
{
-#ifndef NDEBUG
-# if defined (__linux__)
- /* We assume that proper use of msleep() will not use a constant period...
- * Media synchronization is likely to use mwait() with at least slight
- * sleep length variation at microsecond precision. Network protocols
- * normally have exponential backoffs, or long delays. */
- static __thread unsigned tick_period = 0;
- static __thread unsigned tick_frequency = 0;
- if (tick_period != delay)
- tick_frequency = 0;
- tick_frequency++;
- tick_period = delay;
- if (delay < (29 * CLOCK_FREQ) && tick_frequency == 20)
- {
- fprintf (stderr, "Likely bogus delay(%"PRIu64"µs) ", delay);
- vlc_backtrace ();
- }
- //fprintf (stderr, "%u, %u\n", tick_period, tick_frequency);
-# endif
-#endif
-
#if defined( HAVE_CLOCK_NANOSLEEP )
lldiv_t d = lldiv( delay, 1000000 );
struct timespec ts = { d.quot, d.rem * 1000 };
#elif defined( HAVE_KERNEL_OS_H )
snooze( delay );
-#elif defined( WIN32 ) || defined( UNDER_CE )
+#elif defined( WIN32 ) || defined( UNDER_CE ) || defined( __APPLE__ )
mwait (mdate () + delay);
#elif defined( HAVE_NANOSLEEP )