Ticket #4733: eitcrash.diff

File eitcrash.diff, 7.3 KB (added by Janne Grunau, 16 years ago)

original patch converting most of the threads to QThread from David

  • libs/libmythtv/eitscanner.h

     
    22#ifndef EITSCANNER_H
    33#define EITSCANNER_H
    44
    5 // C includes
    6 #include <pthread.h>
    7 
    85// Qt includes
    96#include <qmutex.h>
    107#include <qobject.h>
    118#include <qdatetime.h>
    129#include <qstringlist.h>
    1310#include <qwaitcondition.h>
     11#include <qthread.h>
    1412
    1513class TVRec;
    1614class ChannelBase;
     
    2725    virtual void SetEITRate(float rate) = 0;
    2826};
    2927
     28class EITScanner;
     29
     30class EITThread : public QThread
     31{
     32  public:
     33    virtual void run();
     34    EITScanner   *scanner;
     35};
     36
    3037class EITScanner
    3138{
     39  friend class EITThread;
     40
    3241  public:
    3342    EITScanner(uint cardnum);
    3443    ~EITScanner() { TeardownAll(); }
     
    3948    void StartActiveScan(TVRec*, uint max_seconds_per_source,
    4049                         bool ignore_source);
    4150
    42     void StopActiveScan(void);       
     51    void StopActiveScan(void);
    4352
     53  protected:
     54    void RunEventLoop(void);
     55
    4456  private:
    4557    void TeardownAll(void);
    46     void RunEventLoop(void);
    4758    static void *SpawnEventLoop(void*);
    4859    static void RescheduleRecordings(void);
    4960
     
    5263    EITSource       *eitSource;
    5364
    5465    EITHelper       *eitHelper;
    55     pthread_t        eventThread;
     66    EITThread        eventThread;
    5667    bool             exitThread;
    5768    QWaitCondition   exitThreadCond;
    5869
  • libs/libmythtv/tv_rec.cpp

     
    259259    overRecordSecCat  = gContext->GetNumSetting("CategoryOverTime") * 60;
    260260    overRecordCategory= gContext->GetSetting("OverTimeCategory");
    261261
    262     pthread_create(&event_thread, NULL, EventThread, this);
     262    tvthread.thetv = this;
     263    tvthread.start();
    263264
    264265    WaitForEventThreadSleep();
    265266
     
    288289    if (HasFlags(kFlagRunMainLoop))
    289290    {
    290291        ClearFlags(kFlagRunMainLoop);
    291         pthread_join(event_thread, NULL);
     292        tvthread.wait();
    292293    }
    293294
    294295    TeardownSignalMonitor();
     
    10881089        gContext->dispatch(me);
    10891090
    10901091        recorder->StopRecording();
    1091         pthread_join(recorder_thread, NULL);
     1092        recthread.wait();
    10921093    }
    10931094    ClearFlags(kFlagRecorderRunning);
    10941095
     
    12391240#endif // USING_V4L
    12401241}
    12411242
    1242 /** \fn TVRec::EventThread(void*)
    1243  *  \brief Thunk that allows event pthread to call RunTV().
     1243/** \fn TVThread::run(void)
     1244 *  \brief Thunk that allows event Qthread to call RunTV().
    12441245 */
    1245 void *TVRec::EventThread(void *param)
     1246void TVThread::run(void)
    12461247{
    1247     TVRec *thetv = (TVRec *)param;
    12481248    thetv->RunTV();
    1249     return NULL;
    12501249}
    12511250
    1252 /** \fn TVRec::RecorderThread(void*)
    1253  *  \brief Thunk that allows recorder pthread to
     1251/** \fn RECThread::run(void)
     1252 *  \brief Thunk that allows recorder Qthread to
    12541253 *         call RecorderBase::StartRecording().
    12551254 */
    1256 void *TVRec::RecorderThread(void *param)
     1255void RECThread::run(void)
    12571256{
    1258     RecorderBase *recorder = (RecorderBase *)param;
    12591257    recorder->StartRecording();
    1260     return NULL;
    12611258}
    12621259
    12631260bool get_use_eit(uint cardid)
     
    40034000    }
    40044001#endif
    40054002
    4006     pthread_create(&recorder_thread, NULL, TVRec::RecorderThread, recorder);
     4003    recthread.recorder = recorder;
     4004    recthread.start();
    40074005
    40084006    // Wait for recorder to start.
    40094007    stateChangeLock.unlock();
  • libs/libmythtv/eitscanner.cpp

     
    3636    QStringList langPref = iso639_get_language_list();
    3737    eitHelper->SetLanguagePreferences(langPref);
    3838
    39     pthread_create(&eventThread, NULL, SpawnEventLoop, this);
     39    // Start scanner with Idle scheduling priority, to avoid problems with recordings.
     40    eventThread.scanner = this;
     41    eventThread.start(QThread::IdlePriority);
    4042}
    4143
    4244void EITScanner::TeardownAll(void)
     
    4648    {
    4749        exitThread = true;
    4850        exitThreadCond.wakeAll();
    49         pthread_join(eventThread, NULL);
     51        eventThread.wait();
    5052    }
    5153
    5254    if (eitHelper)
     
    5658    }
    5759}
    5860
    59 /** \fn EITScanner::SpawnEventLoop(void*)
    60  *  \brief Thunk that allows scanner_thread pthread to
     61/** \fn EITThread::run(void)
     62 *  \brief Thunk that allows scanner Qthread to
    6163 *         call EITScanner::RunScanner().
    6264 */
    63 void *EITScanner::SpawnEventLoop(void *param)
     65void EITThread::run(void)
    6466{
    65     // Lower scheduling priority, to avoid problems with recordings.
    66     if (setpriority(PRIO_PROCESS, 0, 19))
    67         VERBOSE(VB_IMPORTANT, LOC + "Setting priority failed." + ENO);
    68     EITScanner *scanner = (EITScanner*) param;
    6967    scanner->RunEventLoop();
    70     return NULL;
    7168}
    7269
    7370/** \fn EITScanner::RunEventLoop()
  • libs/libmythtv/tv_rec.h

     
    22#define TVREC_H
    33
    44#include <qstring.h>
    5 #include <pthread.h>
     5#include <qthread.h>
    66#include <qdatetime.h>
    77#include <qvaluelist.h>
    88#include <qptrlist.h>
     
    149149};
    150150typedef QMap<uint,PendingInfo> PendingMap;
    151151
     152class RECThread : public QThread
     153{
     154  public:
     155    virtual void run();
     156    RecorderBase *recorder;
     157};
     158
     159class MPUBLIC TVRec;
     160
     161class TVThread : public QThread
     162{
     163  public:
     164    virtual void run();
     165    TVRec        *thetv;
     166};
     167
    152168class MPUBLIC TVRec : public QObject
    153169{
    154170    friend class TuningRequest;
     171    friend class TVThread;
    155172    Q_OBJECT
    156173  public:
    157174    TVRec(int capturecardnum);
     
    332349    SignalMonitor    *signalMonitor;
    333350    EITScanner       *scanner;
    334351
    335     // Various threads
    336     /// Event processing thread, runs RunTV().
    337     pthread_t event_thread;
    338     /// Recorder thread, runs RecorderBase::StartRecording()
    339     pthread_t recorder_thread;
    340 
    341352    // Configuration variables from database
    342353    bool    eitIgnoresSource;
    343354    bool    transcodeFirst;
     
    400411    static QMutex            cardsLock;
    401412    static QMap<uint,TVRec*> cards;
    402413
     414    // Various threads
     415    /// Recorder thread, runs RecorderBase::StartRecording()
     416    RECThread    recthread;
     417
     418    /// Event processing thread, runs RunTV().
     419    TVThread     tvthread;
     420
    403421  public:
    404422    static const uint kSignalMonitoringRate;
    405423
  • libs/libmythtv/mpeg/pespacket.cpp

     
    4848
    4949    if (ccExp == cc)
    5050    {
    51         if (_pesdataSize + payloadSize >= _allocSize)
     51        uint sz = _allocSize;
     52
     53        while (_pesdataSize + payloadSize >= sz)
    5254        {
    53             uint sz = (((_allocSize * 2) + 4095) / 4096) * 4096;
     55            if (sz > 0)
     56            {
     57                sz = (((sz * 2) + 4095) / 4096) * 4096;
     58            }
     59            else
     60            {
     61                sz = 4096;
     62            }
     63        }
     64
     65        if (sz != _allocSize)
     66        {
    5467            unsigned char *nbuf = pes_alloc(sz);
     68
     69            if (!nbuf)
     70            {
     71                return true;
     72            }
     73
    5574            memcpy(nbuf, _fullbuffer, _pesdataSize);
    5675            pes_free(_fullbuffer);
    5776            _fullbuffer = nbuf;