mirror of
https://github.com/mpv-player/mpv
synced 2025-01-13 02:16:40 +00:00
cache: fix build on OSX (again)
OSX doesn't support the POSIX API we were using. We check for _POSIX_TIMERS. 0 or -1 means unsupported. See: http://pubs.opengroup.org/onlinepubs/009696699/functions/clock_getres.html http://pubs.opengroup.org/onlinepubs/009696699/basedefs/unistd.h.html The workaround of using gettimeofday() is suggested by Apple: https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man3/pthread_cond_timedwait.3.html Thanks to AStorm for providing help here.
This commit is contained in:
parent
fa30dc4154
commit
c412f7daf6
@ -131,7 +131,14 @@ static int cond_timed_wait(pthread_cond_t *cond, pthread_mutex_t *mutex,
|
||||
double timeout)
|
||||
{
|
||||
struct timespec ts;
|
||||
#if _POSIX_TIMERS > 0
|
||||
clock_gettime(CLOCK_REALTIME, &ts);
|
||||
#else
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
ts.tv_sec = tv.tv_sec;
|
||||
ts.tv_nsec = tv.tv_usec * 1000UL;
|
||||
#endif
|
||||
unsigned long seconds = (int)timeout;
|
||||
unsigned long nsecs = (timeout - seconds) * 1000000000UL;
|
||||
if (nsecs + ts.tv_nsec >= 1000000000UL) {
|
||||
|
Loading…
Reference in New Issue
Block a user