more const, get rid of forced sleep (nw)

This commit is contained in:
Vas Crabb 2017-08-02 03:33:02 +10:00
parent ecad41a8ec
commit a19a685621

View File

@ -884,11 +884,7 @@ osd_ticks_t video_manager::throttle_until_ticks(osd_ticks_t target_ticks)
{ {
// we're allowed to sleep via the OSD code only if we're configured to do so // we're allowed to sleep via the OSD code only if we're configured to do so
// and we're not frameskipping due to autoframeskip, or if we're paused // and we're not frameskipping due to autoframeskip, or if we're paused
bool allowed_to_sleep = false; bool const allowed_to_sleep = (machine().options().sleep() && (!effective_autoframeskip() || effective_frameskip() == 0)) || machine().paused();
if (machine().options().sleep() && (!effective_autoframeskip() || effective_frameskip() == 0))
allowed_to_sleep = true;
if (machine().paused())
allowed_to_sleep = true;
// loop until we reach our target // loop until we reach our target
g_profiler.start(PROFILER_IDLE); g_profiler.start(PROFILER_IDLE);
@ -896,30 +892,25 @@ osd_ticks_t video_manager::throttle_until_ticks(osd_ticks_t target_ticks)
while (current_ticks < target_ticks) while (current_ticks < target_ticks)
{ {
// compute how much time to sleep for, taking into account the average oversleep // compute how much time to sleep for, taking into account the average oversleep
osd_ticks_t delta = (target_ticks - current_ticks) * 1000 / (1000 + m_average_oversleep); osd_ticks_t const delta = (target_ticks - current_ticks) * 1000 / (1000 + m_average_oversleep);
if (!delta)
delta = 1;
// see if we can sleep // see if we can sleep
bool slept = false; bool const slept = allowed_to_sleep && delta;
if (allowed_to_sleep) if (slept)
{
osd_sleep(delta); osd_sleep(delta);
slept = true;
}
// read the new value // read the new value
osd_ticks_t new_ticks = osd_ticks(); osd_ticks_t const new_ticks = osd_ticks();
// keep some metrics on the sleeping patterns of the OSD layer // keep some metrics on the sleeping patterns of the OSD layer
if (slept) if (slept)
{ {
// if we overslept, keep an average of the amount // if we overslept, keep an average of the amount
osd_ticks_t actual_ticks = new_ticks - current_ticks; osd_ticks_t const actual_ticks = new_ticks - current_ticks;
if (actual_ticks > delta) if (actual_ticks > delta)
{ {
// take 90% of the previous average plus 10% of the new value // take 90% of the previous average plus 10% of the new value
osd_ticks_t oversleep_milliticks = 1000 * (actual_ticks - delta) / delta; osd_ticks_t const oversleep_milliticks = 1000 * (actual_ticks - delta) / delta;
m_average_oversleep = (m_average_oversleep * 99 + oversleep_milliticks) / 100; m_average_oversleep = (m_average_oversleep * 99 + oversleep_milliticks) / 100;
if (LOG_THROTTLE) if (LOG_THROTTLE)