Commit 6dc4e260 authored by Pierre d'Herbemont's avatar Pierre d'Herbemont

pthread: Use pthread_cond_timedwait_relative_np() on Darwin.

Switching to the non monotonic clock was still unsafe.
This fixes some sync issues on the iPad.
parent 532b014a
...@@ -380,22 +380,28 @@ int vlc_cond_timedwait (vlc_cond_t *p_condvar, vlc_mutex_t *p_mutex, ...@@ -380,22 +380,28 @@ int vlc_cond_timedwait (vlc_cond_t *p_condvar, vlc_mutex_t *p_mutex,
mtime_t deadline) mtime_t deadline)
{ {
#if defined(__APPLE__) && !defined(__powerpc__) && !defined( __ppc__ ) && !defined( __ppc64__ ) #if defined(__APPLE__) && !defined(__powerpc__) && !defined( __ppc__ ) && !defined( __ppc64__ )
/* mdate() is mac_absolute_time on OSX, which we must convert to do /* mdate() is the monotonic clock, timedwait origin is gettimeofday() which
* the same base than gettimeofday() which pthread_cond_timedwait * isn't monotonic. Use imedwait_relative_np() instead
* relies on. */ */
mtime_t oldbase = mdate(); mtime_t base = mdate();
struct timeval tv; deadline -= base;
gettimeofday(&tv, NULL); if (deadline < 0)
mtime_t newbase = (mtime_t)tv.tv_sec * 1000000 + (mtime_t) tv.tv_usec; deadline = 0;
deadline = deadline - oldbase + newbase;
#endif
lldiv_t d = lldiv( deadline, CLOCK_FREQ ); lldiv_t d = lldiv( deadline, CLOCK_FREQ );
struct timespec ts = { d.quot, d.rem * (1000000000 / CLOCK_FREQ) }; struct timespec ts = { d.quot, d.rem * (1000000000 / CLOCK_FREQ) };
int val = pthread_cond_timedwait_relative_np(p_condvar, p_mutex, &ts);
if (val != ETIMEDOUT)
VLC_THREAD_ASSERT ("timed-waiting on condition");
return val;
#else
lldiv_t d = lldiv( deadline, CLOCK_FREQ );
struct timespec ts = { d.quot, d.rem * (1000000000 / CLOCK_FREQ) };
int val = pthread_cond_timedwait (p_condvar, p_mutex, &ts); int val = pthread_cond_timedwait (p_condvar, p_mutex, &ts);
if (val != ETIMEDOUT) if (val != ETIMEDOUT)
VLC_THREAD_ASSERT ("timed-waiting on condition"); VLC_THREAD_ASSERT ("timed-waiting on condition");
return val; return val;
#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