~ubuntu-branches/ubuntu/lucid/mythtv/lucid

« back to all changes in this revision

Viewing changes to libs/libmythtv/tv_rec.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Mario Limonciello
  • Date: 2009-10-02 00:23:18 UTC
  • mfrom: (1.1.36 upstream)
  • Revision ID: james.westby@ubuntu.com-20091002002318-5qu2fr0gxl59egft
Tags: 0.22.0~trunk22167-0ubuntu1
* New upstream checkout (r22167).
  - Fixes some segfaults.

Show diffs side-by-side

added added

removed removed

Lines of Context:
128
128
      internalState(kState_None), desiredNextState(kState_None),
129
129
      changeState(false), pauseNotify(true),
130
130
      stateFlags(0), lastTuningRequest(0),
 
131
      triggerEventLoopLock(QMutex::NonRecursive),
 
132
      triggerEventLoopSignal(false),
 
133
      triggerEventSleepLock(QMutex::NonRecursive),
 
134
      triggerEventSleepSignal(false),
131
135
      m_switchingBuffer(false),
132
136
      // Current recording info
133
137
      curRecording(NULL), autoRunJobs(JOB_NONE),
312
316
    SetRingBuffer(NULL);
313
317
}
314
318
 
 
319
void TVRec::WakeEventLoop(void)
 
320
{
 
321
    QMutexLocker locker(&triggerEventLoopLock);
 
322
    triggerEventLoopSignal = true;
 
323
    triggerEventLoopWait.wakeAll();
 
324
}
 
325
 
315
326
/** \fn TVRec::GetState() const
316
327
 *  \brief Returns the TVState of the recorder.
317
328
 *
954
965
 
955
966
    desiredNextState = nextState;
956
967
    changeState = true;
957
 
    triggerEventLoop.wakeAll();
 
968
    WakeEventLoop();
958
969
}
959
970
 
960
971
/** \fn TVRec::SetupRecorder(RecordingProfile&)
1371
1382
    else
1372
1383
        eitScanStartTime = eitScanStartTime.addYears(1);
1373
1384
 
1374
 
    // Qt4 requires a QMutex as a parameter...
1375
 
    // not sure if this is the best solution.  Mutex Must be locked before wait.
1376
 
    QMutex mutex;
1377
 
    mutex.lock();
1378
 
 
1379
1385
    while (HasFlags(kFlagRunMainLoop))
1380
1386
    {
1381
1387
        // If there is a state change queued up, do it...
1543
1549
        // WaitforEventThreadSleep() will still work...
1544
1550
        if (tuningRequests.empty() && !changeState)
1545
1551
        {
1546
 
            triggerEventSleep.wakeAll();
1547
 
            lock.mutex()->unlock();
 
1552
            lock.unlock(); // stateChangeLock
 
1553
 
 
1554
            {
 
1555
                QMutexLocker locker(&triggerEventSleepLock);
 
1556
                triggerEventSleepSignal = true;
 
1557
                triggerEventSleepWait.wakeAll();
 
1558
            }
 
1559
 
1548
1560
            sched_yield();
1549
 
            triggerEventSleep.wakeAll();
1550
 
            triggerEventLoop.wait(&mutex, 1000 /* ms */);
1551
 
            lock.mutex()->lock();
 
1561
 
 
1562
            {
 
1563
                QMutexLocker locker(&triggerEventLoopLock);
 
1564
                // We check tELSignal because it is possible
 
1565
                // that WakeEventLoop() was called since we
 
1566
                // unlocked the stateChangeLock
 
1567
                if (!triggerEventLoopSignal)
 
1568
                {
 
1569
                    triggerEventLoopWait.wait(
 
1570
                        &triggerEventLoopLock, 1000 /* ms */);
 
1571
                }
 
1572
                triggerEventLoopSignal = false;
 
1573
            }
 
1574
 
 
1575
            lock.relock(); // stateChangeLock
1552
1576
        }
1553
1577
    }
1554
1578
 
1559
1583
    }
1560
1584
}
1561
1585
 
 
1586
/** \fn TVRec::WaitForEventThreadSleep(bool wake, ulong time)
 
1587
 *
 
1588
 *  You MUST HAVE the stateChange-lock locked when you call this method!
 
1589
 */
 
1590
 
1562
1591
bool TVRec::WaitForEventThreadSleep(bool wake, ulong time)
1563
1592
{
1564
 
    // Qt4 requires a QMutex as a parameter...
1565
 
    // not sure if this is the best solution.  Mutex Must be locked before wait.
1566
 
    QMutex mutex;
1567
 
    mutex.lock();
1568
 
 
1569
1593
    bool ok = false;
1570
1594
    MythTimer t;
1571
1595
    t.start();
1573
1597
    while (!ok && ((unsigned long) t.elapsed()) < time)
1574
1598
    {
1575
1599
        if (wake)
1576
 
            triggerEventLoop.wakeAll();
 
1600
            WakeEventLoop();
1577
1601
 
1578
1602
        stateChangeLock.unlock();
1579
 
        // It is possible for triggerEventSleep.wakeAll() to be sent
1580
 
        // before we enter wait so we only wait 100 ms so we can try
1581
 
        // again a few times before 15 second timeout on frontend...
1582
 
        triggerEventSleep.wait(&mutex, 100);
 
1603
 
 
1604
        sched_yield();
 
1605
 
 
1606
        {
 
1607
            QMutexLocker locker(&triggerEventSleepLock);
 
1608
            if (!triggerEventSleepSignal)
 
1609
                triggerEventSleepWait.wait(&triggerEventSleepLock);
 
1610
            triggerEventSleepSignal = false;
 
1611
        }
 
1612
 
1583
1613
        stateChangeLock.lock();
1584
1614
 
1585
1615
        // verify that we were triggered.
2926
2956
void TVRec::RecorderPaused(void)
2927
2957
{
2928
2958
    if (pauseNotify)
2929
 
    {
2930
 
        QMutexLocker lock(&stateChangeLock);
2931
 
        triggerEventLoop.wakeAll();
2932
 
    }
 
2959
        WakeEventLoop();
2933
2960
}
2934
2961
 
2935
2962
/**
4205
4232
    stateFlags |= f;
4206
4233
    VERBOSE(VB_RECORD, LOC + QString("SetFlags(%1) -> %2")
4207
4234
            .arg(FlagToString(f)).arg(FlagToString(stateFlags)));
4208
 
    triggerEventLoop.wakeAll();
 
4235
    WakeEventLoop();
4209
4236
}
4210
4237
 
4211
4238
void TVRec::ClearFlags(uint f)
4214
4241
    stateFlags &= ~f;
4215
4242
    VERBOSE(VB_RECORD, LOC + QString("ClearFlags(%1) -> %2")
4216
4243
            .arg(FlagToString(f)).arg(FlagToString(stateFlags)));
4217
 
    triggerEventLoop.wakeAll();
 
4244
    WakeEventLoop();
4218
4245
}
4219
4246
 
4220
4247
QString TVRec::FlagToString(uint f)