Ticket #2019: thread_conditions_rev2.patch

File thread_conditions_rev2.patch, 6.2 KB (added by russell@…, 18 years ago)
  • libs/libmythtv/analogscan.h

     
    3535
    3636#include <qobject.h>
    3737#include <qstring.h>
     38#include <qmutex.h>
     39#include <qwaitcondition.h>
    3840#include <pthread.h>
    3941#include "frequencies.h"
    4042
     
    9092    /** @brief Scanning thread*/
    9193    pthread_t thread;
    9294
     95    /** @brief Condition to signal that the scanning thread is running */
     96    QWaitCondition scanThreadCond;
     97    QMutex scanThreadCondLock;
     98
    9399    /** @brief Actual scanning proc */
    94100    void doScan();
    95101    /** @brief Actual thread proc , calls doScan*/
  • libs/libmythtv/tv_play.h

     
    567567    /// runs pipnvp's NuppelVideoPlayer::StartPlaying().
    568568    pthread_t pipdecode;
    569569
     570    /// Condition to signal that the Event thread is up and running
     571    QWaitCondition mainLoopCond;
     572    QMutex mainLoopCondLock;
     573
    570574    // Constants
    571575    static const int kInitFFRWSpeed; ///< 1x, default to normal speed
    572576    static const int kMuteTimeout;   ///< Channel changing mute timeout in msec
  • libs/libmythtv/analogscan.cpp

     
    7676void AnalogScan::doScan()
    7777{
    7878    fRunning = true;
     79    scanThreadCondLock.lock();
     80    scanThreadCond.wakeAll();
     81    scanThreadCondLock.unlock();
    7982
    8083    Channel         *channel = NULL;
    8184    struct CHANLIST *flist   = NULL;
     
    156159    }
    157160
    158161    if (!fRunning)
     162    {
     163        scanThreadCondLock.lock();
    159164        pthread_create(&thread, NULL, spawn, this);
    160     while (!fRunning)
    161         usleep(50);
     165        scanThreadCond.wait(&scanThreadCondLock);
     166        scanThreadCondLock.unlock();
     167    }
     168
    162169    return true;
    163170}
    164171
  • libs/libmythtv/RingBuffer.cpp

     
    629629{
    630630    readaheadrunning = false;
    631631
     632    readAheadRunningCondLock.lock();
    632633    pthread_create(&reader, NULL, StartReader, this);
    633 
    634     while (!readaheadrunning)
    635         usleep(50);
     634    readAheadRunningCond.wait(&readAheadRunningCondLock);
     635    readAheadRunningCondLock.unlock();
    636636}
    637637
    638638/** \fn RingBuffer::KillReadAheadThread(void)
     
    730730    totfree = ReadBufFree();
    731731
    732732    readaheadrunning = true;
     733    readAheadRunningCondLock.lock();
     734    readAheadRunningCond.wakeAll();
     735    readAheadRunningCondLock.unlock();
    733736    while (readaheadrunning)
    734737    {
    735738        if (pausereadthread || writemode)
  • libs/libmythtv/tv_play.cpp

     
    484484        qApp->processEvents();
    485485    }
    486486
     487    mainLoopCondLock.lock();
    487488    pthread_create(&event, NULL, EventThread, this);
     489    mainLoopCond.wait(&mainLoopCondLock);
     490    mainLoopCondLock.unlock();
    488491
    489     while (!runMainLoop && !IsErrored())
    490         usleep(50);
    491 
    492492    return !IsErrored();
    493493}
    494494
     
    10841084 */
    10851085bool TV::InStateChange() const
    10861086{
    1087     if (stateLock.locked())
     1087    if (!stateLock.tryLock())
    10881088        return true;
    1089     stateLock.lock();
    10901089    bool inStateChange = nextStates.size() > 0;
    10911090    stateLock.unlock();
    10921091    return inStateChange;
     
    13091308        nvp->SetWatchingRecording(true);
    13101309
    13111310    int udp_port = gContext->GetNumSetting("UDPNotifyPort");
    1312      if (udp_port > 0)
    1313          udpnotify = new UDPNotify(this, udp_port);
    1314      else
    1315          udpnotify = NULL;
     1311    if (udp_port > 0)
     1312        udpnotify = new UDPNotify(this, udp_port);
     1313    else
     1314        udpnotify = NULL;
    13161315}
    13171316
    13181317
     
    15031502    runMainLoop = true;
    15041503    exitPlayer = false;
    15051504
     1505    mainLoopCondLock.lock();
     1506    mainLoopCond.wakeAll();
     1507    mainLoopCondLock.unlock();
     1508
    15061509    while (runMainLoop)
    15071510    {
    15081511        stateLock.lock();
  • libs/libmythtv/RingBuffer.h

     
    173173
    174174    long long readAdjust;
    175175
     176    /// Condition to signal that the read ahead thread is running
     177    QWaitCondition readAheadRunningCond;
     178    QMutex readAheadRunningCondLock;
     179 
    176180    // constants
    177181    static const uint kBufferSize;
    178182    static const uint kReadTestSize;
  • programs/mythfrontend/networkcontrol.h

     
    6666    QMutex nrLock;
    6767
    6868    pthread_t command_thread;
    69     bool runCommandThread;
    70     bool commandThreadRunning;
    7169};
    7270
    7371#endif
  • programs/mythfrontend/networkcontrol.cpp

     
    103103    keyMap["f11"]                    = Qt::Key_F11;
    104104    keyMap["f12"]                    = Qt::Key_F12;
    105105
    106     runCommandThread = true;
    107 
    108106    pthread_attr_t attr;
    109107    pthread_attr_init(&attr);
    110108    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
     
    123121
    124122    notifyDataAvailable();
    125123
    126     runCommandThread = false;
    127 
    128     while (commandThreadRunning)
    129         usleep(1000);
    130 
     124    pthread_cancel(command_thread);
    131125    pthread_join(command_thread, NULL);
    132126}
    133127
     
    143137{
    144138    QString command;
    145139    int commands = 0;
    146     commandThreadRunning = true;
    147140
    148     while(runCommandThread)
     141    for (;;)
    149142    {
     143        pthread_testcancel();
     144
    150145        ncLock.lock();
    151146        commands = networkControlCommands.size();
    152147        ncLock.unlock();
     
    167162
    168163        usleep(50000);
    169164    }
    170 
    171     commandThreadRunning = false;
    172165}
    173166
    174167void NetworkControl::processNetworkControlCommand(QString command)