Ticket #2019: thread_conditions.patch

File thread_conditions.patch, 4.0 KB (added by russell@…, 19 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
     
    15031503    runMainLoop = true;
    15041504    exitPlayer = false;
    15051505
     1506    mainLoopCondLock.lock();
     1507    mainLoopCond.wakeAll();
     1508    mainLoopCondLock.unlock();
     1509
    15061510    while (runMainLoop)
    15071511    {
    15081512        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;