From 2b25244c95c9c1b30d2f64937ba7cf861dbb7168 Mon Sep 17 00:00:00 2001 From: Flyinghead Date: Tue, 30 Oct 2018 10:56:25 +0100 Subject: [PATCH] cResetEvent: needs absolute timeout value. Fixes Android FPS drop. --- core/linux/common.cpp | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/core/linux/common.cpp b/core/linux/common.cpp index da04bf40f..a07ce6afe 100644 --- a/core/linux/common.cpp +++ b/core/linux/common.cpp @@ -23,6 +23,10 @@ #include #include #endif +#if HOST_OS == OS_DARWIN +#include +#include +#endif #include #include "hw/sh4/dyna/blockmanager.h" @@ -171,17 +175,34 @@ void cResetEvent::Reset()//reset } bool cResetEvent::Wait(u32 msec)//Wait for signal , then reset { - bool rc = true; pthread_mutex_lock( &mutx ); if (!state) { struct timespec ts; - ts.tv_sec = msec / 1000; - ts.tv_nsec = (msec % 1000) * 1000000; - rc = pthread_cond_timedwait( &cond, &mutx, &ts ) == 0; +#if HOST_OS == OS_DARWIN + // OSX doesn't have clock_gettime. + clock_serv_t cclock; + mach_timespec_t mts; + + host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock); + clock_get_time(cclock, &mts); + mach_port_deallocate(mach_task_self(), cclock); + ts.tv_sec = mts.tv_sec; + ts.tv_nsec = mts.tv_nsec; +#else + clock_gettime(CLOCK_REALTIME, &ts); +#endif + ts.tv_sec += msec / 1000; + ts.tv_nsec += (msec % 1000) * 1000000; + while (ts.tv_nsec > 1000000000) + { + ts.tv_nsec -= 1000000000; + ts.tv_sec++; + } + pthread_cond_timedwait( &cond, &mutx, &ts ); } - if (rc) - state=false; + bool rc = state; + state=false; pthread_mutex_unlock( &mutx ); return rc;