Skip to content

Commit

Permalink
Avoid busy looping in some cases in the scheduler when the time to
Browse files Browse the repository at this point in the history
check on slaves that cat be put to sleep has already passed.  Thanks
to lucylangthorne55 for helping to debug this issue.

Fixes #13072
  • Loading branch information
gigem committed Aug 9, 2017
1 parent a1823f3 commit 871f9e8
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions mythtv/programs/mythbackend/scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2077,7 +2077,7 @@ void Scheduler::run(void)
bool blockShutdown =
gCoreContext->GetNumSetting("blockSDWUwithoutClient", 1);
bool firstRun = true;
QDateTime lastSleepCheck = MythDate::current().addDays(-1);
QDateTime nextSleepCheck = MythDate::current();
RecIter startIter = reclist.begin();
QDateTime idleSince = QDateTime();
int schedRunTime = 0; // max scheduler run time in seconds
Expand Down Expand Up @@ -2105,7 +2105,7 @@ void Scheduler::run(void)
sched_sleep = min(sched_sleep, 15000);
bool haveRequests = HaveQueuedRequests();
int const kSleepCheck = 300;
bool checkSlaves = lastSleepCheck.secsTo(curtime) >= kSleepCheck;
bool checkSlaves = curtime >= nextSleepCheck;

// If we're about to start a recording don't do any reschedules...
// instead sleep for a bit
Expand Down Expand Up @@ -2166,12 +2166,18 @@ void Scheduler::run(void)
{
// Check for slaves that can be put to sleep.
PutInactiveSlavesToSleep();
lastSleepCheck = MythDate::current();
nextSleepCheck = MythDate::current().addSecs(kSleepCheck);
checkSlaves = false;
}
}

nextStartTime = MythDate::current().addDays(14);
nextWakeTime = lastSleepCheck.addSecs(kSleepCheck);
// If checkSlaves is still set, choose a reasonable wake time
// in the future instead of one that we know is in the past.
if (checkSlaves)
nextWakeTime = MythDate::current().addSecs(kSleepCheck);
else
nextWakeTime = nextSleepCheck;

// Skip past recordings that are already history
// (i.e. AddHistory() has been called setting oldrecstatus)
Expand Down

0 comments on commit 871f9e8

Please sign in to comment.