Permalink
Browse files

audio: Added busywait performance fix

  • Loading branch information...
fzurita committed Feb 25, 2016
1 parent 33d5969 commit f30a8da8a06e1eeab766904189bd1292a0aa318a
Showing with 25 additions and 4 deletions.
  1. +25 −4 jni/mupen64plus-audio-sles/main.cpp
@@ -667,6 +667,7 @@ bool isSpeedLimiterEnabled(void)
EXPORT void CALL AiLenChanged(void)
{
static const bool sleepPerfFixEnabled = true;
static const double minSleepNeeded = -0.1;
static const double maxSleepNeeded = 0.1;
if (critical_failure == 1)
@@ -723,10 +724,30 @@ EXPORT void CALL AiLenChanged(void)
if(sleepNeeded > 0.0 && sleepNeeded < maxSleepNeeded)
{
timespec sleepTime;
sleepTime.tv_sec = static_cast<time_t>(sleepNeeded);
sleepTime.tv_nsec = (sleepNeeded - sleepTime.tv_sec)*1e9;
nanosleep(&sleepTime, NULL );
if(sleepPerfFixEnabled)
{
double endTime = timeDouble + sleepNeeded;
timespec time;
clock_gettime(CLOCK_REALTIME, &time);
double currTime = static_cast<double>(time.tv_sec) +
static_cast<double>(time.tv_nsec)/1.0e9;
while(currTime < endTime)
{
clock_gettime(CLOCK_REALTIME, &time);
currTime = static_cast<double>(time.tv_sec) +
static_cast<double>(time.tv_nsec)/1.0e9;
}
}
else
{
timespec sleepTime;
sleepTime.tv_sec = static_cast<time_t>(sleepNeeded);
sleepTime.tv_nsec = (sleepNeeded - sleepTime.tv_sec)*1e9;
nanosleep(&sleepTime, NULL );
}
}
}
}

0 comments on commit f30a8da

Please sign in to comment.