Ticket #10770: deadlock1-0.25.patch

File deadlock1-0.25.patch, 4.1 KB (added by gigem, 12 years ago)
  • mythtv/programs/mythbackend/scheduler.cpp

    diff --git a/mythtv/programs/mythbackend/scheduler.cpp b/mythtv/programs/mythbackend/scheduler.cpp
    index 1d165c4..6a7ba6d 100644
    a b bool Scheduler::ChangeRecordingEnd(RecordingInfo *oldp, RecordingInfo *newp) 
    690690    }
    691691
    692692    EncoderLink *tv = (*m_tvList)[oldp->GetCardID()];
     693    lockit.unlock();
    693694    RecStatusType rs = tv->StartRecording(oldp);
     695    lockit.relock();
    694696    if (rs != rsRecording)
    695697    {
    696698        LOG(VB_GENERAL, LOG_ERR,
    void Scheduler::SlaveDisconnected(uint cardid) 
    817819
    818820void Scheduler::BuildWorkList(void)
    819821{
    820     reclist_changed = false;
    821 
    822822    RecIter i = reclist.begin();
    823823    for (; i != reclist.end(); ++i)
    824824    {
    void Scheduler::run(void) 
    17951795
    17961796    while (doRun)
    17971797    {
     1798        reclist_changed = false;
     1799
    17981800        QDateTime curtime = QDateTime::currentDateTime();
    17991801        bool statuschanged = false;
    18001802        int secs_to_next = (startIter != reclist.end()) ?
    void Scheduler::run(void) 
    19051907                **it, statuschanged, prerollseconds, tuningTimeout);
    19061908        }
    19071909
     1910        // HandleRecording() and HandleTuning() temporarily unlocks
     1911        // schedLock.  If anything changed, reclist iterators could be
     1912        // invalidated so start over.
     1913        if (reclist_changed)
     1914            continue;
     1915
    19081916        /// Wake any slave backends that need waking
    19091917        curtime = QDateTime::currentDateTime();
    19101918        for (RecIter it = startIter; it != reclist.end(); ++it)
    bool Scheduler::HandleRecording( 
    22832291    if (ri.GetRecordingStatus() == rsTuning)
    22842292    {
    22852293        HandleTuning(ri, statuschanged, tuningTimeout);
    2286         return false;
     2294        return reclist_changed;
    22872295    }
    22882296
    22892297    if (ri.GetRecordingStatus() != rsWillRecord)
    bool Scheduler::HandleRecording( 
    23512359        return false;
    23522360    }
    23532361
    2354     if ((prerollseconds > 0) && !IsBusyRecording(&ri))
     2362    schedLock.unlock();
     2363    bool isBusyRecording = IsBusyRecording(&ri);
     2364    schedLock.lock();
     2365    if (reclist_changed)
     2366        return reclist_changed;
     2367
     2368    if ((prerollseconds > 0) && !isBusyRecording)
    23552369    {
    23562370        // Will use pre-roll settings only if no other
    23572371        // program is currently being recorded
    bool Scheduler::HandleRecording( 
    24442458    {
    24452459        if (ri.GetRecordingStatus() == rsWillRecord)
    24462460        {
     2461            schedLock.unlock();
    24472462            recStatus = nexttv->StartRecording(&ri);
    2448             ri.AddHistory(false);
     2463            schedLock.lock();
    24492464
    24502465            // activate auto expirer
    24512466            if (m_expirer)
    bool Scheduler::HandleRecording( 
    24562471    HandleRecordingStatusChange(ri, recStatus, details);
    24572472    statuschanged = true;
    24582473
    2459     return false;
     2474    return reclist_changed;
    24602475}
    24612476
    24622477void Scheduler::HandleRecordingStatusChange(
    void Scheduler::HandleRecordingStatusChange( 
    24672482
    24682483    ri.SetRecordingStatus(recStatus);
    24692484
    2470     if (rsTuning != recStatus)
    2471     {
    2472         bool doSchedAfterStart =
    2473             ((rsRecording != recStatus) && (rsTuning != recStatus)) ||
    2474             schedAfterStartMap[ri.GetRecordingRuleID()] ||
    2475             (ri.GetParentRecordingRuleID() &&
    2476              schedAfterStartMap[ri.GetParentRecordingRuleID()]);
    2477         ri.AddHistory(doSchedAfterStart);
    2478     }
     2485    bool doSchedAfterStart =
     2486        recStatus != rsTuning &&
     2487        (recStatus != rsRecording ||
     2488         schedAfterStartMap[ri.GetRecordingRuleID()] ||
     2489         (ri.GetParentRecordingRuleID() &&
     2490          schedAfterStartMap[ri.GetParentRecordingRuleID()]));
     2491    ri.AddHistory(doSchedAfterStart);
    24792492
    24802493    QString msg = (rsRecording == recStatus) ?
    24812494        QString("Started recording") :
    void Scheduler::HandleTuning( 
    25162529    }
    25172530    else if (tuningTimeout > 0)
    25182531    {
     2532        schedLock.unlock();
    25192533        recStatus = (*tvit)->GetRecordingStatus();
     2534        schedLock.lock();
     2535        if (reclist_changed)
     2536            return;
     2537
    25202538        if (rsTuning == recStatus)
    25212539        {
    25222540            // If tuning is still taking place this long after we