Ticket #2019: thread_conditions_rev2.patch
File thread_conditions_rev2.patch, 6.2 KB (added by , 18 years ago) |
---|
-
libs/libmythtv/analogscan.h
35 35 36 36 #include <qobject.h> 37 37 #include <qstring.h> 38 #include <qmutex.h> 39 #include <qwaitcondition.h> 38 40 #include <pthread.h> 39 41 #include "frequencies.h" 40 42 … … 90 92 /** @brief Scanning thread*/ 91 93 pthread_t thread; 92 94 95 /** @brief Condition to signal that the scanning thread is running */ 96 QWaitCondition scanThreadCond; 97 QMutex scanThreadCondLock; 98 93 99 /** @brief Actual scanning proc */ 94 100 void doScan(); 95 101 /** @brief Actual thread proc , calls doScan*/ -
libs/libmythtv/tv_play.h
567 567 /// runs pipnvp's NuppelVideoPlayer::StartPlaying(). 568 568 pthread_t pipdecode; 569 569 570 /// Condition to signal that the Event thread is up and running 571 QWaitCondition mainLoopCond; 572 QMutex mainLoopCondLock; 573 570 574 // Constants 571 575 static const int kInitFFRWSpeed; ///< 1x, default to normal speed 572 576 static const int kMuteTimeout; ///< Channel changing mute timeout in msec -
libs/libmythtv/analogscan.cpp
76 76 void AnalogScan::doScan() 77 77 { 78 78 fRunning = true; 79 scanThreadCondLock.lock(); 80 scanThreadCond.wakeAll(); 81 scanThreadCondLock.unlock(); 79 82 80 83 Channel *channel = NULL; 81 84 struct CHANLIST *flist = NULL; … … 156 159 } 157 160 158 161 if (!fRunning) 162 { 163 scanThreadCondLock.lock(); 159 164 pthread_create(&thread, NULL, spawn, this); 160 while (!fRunning) 161 usleep(50); 165 scanThreadCond.wait(&scanThreadCondLock); 166 scanThreadCondLock.unlock(); 167 } 168 162 169 return true; 163 170 } 164 171 -
libs/libmythtv/RingBuffer.cpp
629 629 { 630 630 readaheadrunning = false; 631 631 632 readAheadRunningCondLock.lock(); 632 633 pthread_create(&reader, NULL, StartReader, this); 633 634 while (!readaheadrunning) 635 usleep(50); 634 readAheadRunningCond.wait(&readAheadRunningCondLock); 635 readAheadRunningCondLock.unlock(); 636 636 } 637 637 638 638 /** \fn RingBuffer::KillReadAheadThread(void) … … 730 730 totfree = ReadBufFree(); 731 731 732 732 readaheadrunning = true; 733 readAheadRunningCondLock.lock(); 734 readAheadRunningCond.wakeAll(); 735 readAheadRunningCondLock.unlock(); 733 736 while (readaheadrunning) 734 737 { 735 738 if (pausereadthread || writemode) -
libs/libmythtv/tv_play.cpp
484 484 qApp->processEvents(); 485 485 } 486 486 487 mainLoopCondLock.lock(); 487 488 pthread_create(&event, NULL, EventThread, this); 489 mainLoopCond.wait(&mainLoopCondLock); 490 mainLoopCondLock.unlock(); 488 491 489 while (!runMainLoop && !IsErrored())490 usleep(50);491 492 492 return !IsErrored(); 493 493 } 494 494 … … 1084 1084 */ 1085 1085 bool TV::InStateChange() const 1086 1086 { 1087 if ( stateLock.locked())1087 if (!stateLock.tryLock()) 1088 1088 return true; 1089 stateLock.lock();1090 1089 bool inStateChange = nextStates.size() > 0; 1091 1090 stateLock.unlock(); 1092 1091 return inStateChange; … … 1309 1308 nvp->SetWatchingRecording(true); 1310 1309 1311 1310 int udp_port = gContext->GetNumSetting("UDPNotifyPort"); 1312 1313 1314 1315 1311 if (udp_port > 0) 1312 udpnotify = new UDPNotify(this, udp_port); 1313 else 1314 udpnotify = NULL; 1316 1315 } 1317 1316 1318 1317 … … 1503 1502 runMainLoop = true; 1504 1503 exitPlayer = false; 1505 1504 1505 mainLoopCondLock.lock(); 1506 mainLoopCond.wakeAll(); 1507 mainLoopCondLock.unlock(); 1508 1506 1509 while (runMainLoop) 1507 1510 { 1508 1511 stateLock.lock(); -
libs/libmythtv/RingBuffer.h
173 173 174 174 long long readAdjust; 175 175 176 /// Condition to signal that the read ahead thread is running 177 QWaitCondition readAheadRunningCond; 178 QMutex readAheadRunningCondLock; 179 176 180 // constants 177 181 static const uint kBufferSize; 178 182 static const uint kReadTestSize; -
programs/mythfrontend/networkcontrol.h
66 66 QMutex nrLock; 67 67 68 68 pthread_t command_thread; 69 bool runCommandThread;70 bool commandThreadRunning;71 69 }; 72 70 73 71 #endif -
programs/mythfrontend/networkcontrol.cpp
103 103 keyMap["f11"] = Qt::Key_F11; 104 104 keyMap["f12"] = Qt::Key_F12; 105 105 106 runCommandThread = true;107 108 106 pthread_attr_t attr; 109 107 pthread_attr_init(&attr); 110 108 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); … … 123 121 124 122 notifyDataAvailable(); 125 123 126 runCommandThread = false; 127 128 while (commandThreadRunning) 129 usleep(1000); 130 124 pthread_cancel(command_thread); 131 125 pthread_join(command_thread, NULL); 132 126 } 133 127 … … 143 137 { 144 138 QString command; 145 139 int commands = 0; 146 commandThreadRunning = true;147 140 148 while(runCommandThread)141 for (;;) 149 142 { 143 pthread_testcancel(); 144 150 145 ncLock.lock(); 151 146 commands = networkControlCommands.size(); 152 147 ncLock.unlock(); … … 167 162 168 163 usleep(50000); 169 164 } 170 171 commandThreadRunning = false;172 165 } 173 166 174 167 void NetworkControl::processNetworkControlCommand(QString command)