diff --git a/mythtv/libs/libmythtv/dtvsignalmonitor.cpp b/mythtv/libs/libmythtv/dtvsignalmonitor.cpp index 552d4d13307..d2e55cc1294 100644 --- a/mythtv/libs/libmythtv/dtvsignalmonitor.cpp +++ b/mythtv/libs/libmythtv/dtvsignalmonitor.cpp @@ -59,9 +59,9 @@ DTVChannel *DTVSignalMonitor::GetDTVChannel(void) return dynamic_cast(channel); } -QStringList DTVSignalMonitor::GetStatusList(bool kick) +QStringList DTVSignalMonitor::GetStatusList(void) const { - QStringList list = SignalMonitor::GetStatusList(kick); + QStringList list = SignalMonitor::GetStatusList(); QMutexLocker locker(&statusLock); // mpeg tables @@ -526,35 +526,3 @@ bool DTVSignalMonitor::IsAllGood(void) const return true; } - -/** \fn SignalMonitor::WaitForLock(int) - * \brief Wait for a StatusSignaLock(int) of true. - * - * This can be called only after the signal - * monitoring thread has been started. - * - * \param timeout maximum time to wait in milliseconds. - * \return true if signal was acquired. - */ -bool DTVSignalMonitor::WaitForLock(int timeout) -{ - statusLock.lock(); - if (-1 == timeout) - timeout = signalLock.GetTimeout(); - statusLock.unlock(); - if (timeout < 0) - return false; - - MythTimer t; - t.start(); - while (t.elapsed()IsExternalChannelChangeSupported()) @@ -233,11 +233,10 @@ void SignalMonitor::Start() DBG_SM("Start", "begin"); { QMutexLocker locker(&startStopLock); - + exit = false; start(); - while (!running) - usleep(5000); + startStopWait.wait(locker.mutex()); } DBG_SM("Start", "end"); } @@ -248,33 +247,19 @@ void SignalMonitor::Start() void SignalMonitor::Stop() { DBG_SM("Stop", "begin"); + + QMutexLocker locker(&startStopLock); + exit = true; + if (running) { - QMutexLocker locker(&startStopLock); - if (running) - { - exit = true; - wait(); - } + locker.unlock(); + wait(); } - DBG_SM("Stop", "end"); -} -/** \fn SignalMonitor::Kick() - * \brief Wake up monitor thread, and wait for - * UpdateValue() to execute once. - */ -void SignalMonitor::Kick() -{ - update_done = false; - - //pthread_kill(monitor_thread, SIGALRM); - - while (!update_done) - usleep(50); + DBG_SM("Stop", "end"); } -/** \fn SignalMonitor::GetStatusList(bool) - * \brief Returns QStringList containing all signals and their current +/** \brief Returns QStringList containing all signals and their current * values. * * This serializes the signal monitoring values so that they can @@ -282,18 +267,9 @@ void SignalMonitor::Kick() * * SignalMonitorValue::Parse(const QStringList&) will convert this * to a vector of SignalMonitorValue instances. - * - * \param kick if true Kick() will be employed so that this - * call will not have to wait for the next signal - * monitoring event. */ -QStringList SignalMonitor::GetStatusList(bool kick) +QStringList SignalMonitor::GetStatusList(void) const { - if (kick && running) - Kick(); - else if (!running) - UpdateValues(); - QStringList list; statusLock.lock(); list<=0) { - QStringList slist = GetStatusList(false); + QStringList slist = GetStatusList(); MythEvent me(QString("SIGNAL %1").arg(capturecardnum), slist); gCoreContext->dispatch(me); - //VERBOSE(VB_GENERAL("sent SIGNAL"); } - usleep(update_rate * 1000); + locker.relock(); + startStopWait.wait(locker.mutex(), update_rate); } // We need to send a last informational message because a // signal update may have come in while we were sleeping // if we are using the multithreaded dtvsignalmonitor. + locker.unlock(); if (notify_frontend && capturecardnum>=0) { - QStringList slist = GetStatusList(false); + QStringList slist = GetStatusList(); MythEvent me(QString("SIGNAL %1").arg(capturecardnum), slist); gCoreContext->dispatch(me); } - running = false; -} - -/** \fn SignalMonitor::WaitForLock(int) - * \brief Wait for a StatusSignaLock(int) of true. - * - * This can be called whether or not the signal - * monitoring thread has been started. - * - * \param timeout maximum time to wait in milliseconds. - * \return true if signal was acquired. - */ -bool SignalMonitor::WaitForLock(int timeout) -{ - statusLock.lock(); - if (-1 == timeout) - timeout = signalLock.GetTimeout(); - statusLock.unlock(); - if (timeout<0) - return false; - - MythTimer t; - t.start(); - if (running) - { - while (t.elapsed() #include #include @@ -42,8 +43,6 @@ class SignalMonitor : protected QThread virtual void Start(); virtual void Stop(); - virtual void Kick(); - virtual bool WaitForLock(int timeout = -1); // // // // // // // // // // // // // // // // // // // // // // // // // Flags // // // // // // // // // // // // // // // // // // // // // @@ -62,7 +61,7 @@ class SignalMonitor : protected QThread bool GetNotifyFrontend() const { return notify_frontend; } /// \brief Returns milliseconds between signal monitoring events. int GetUpdateRate() const { return update_rate; } - virtual QStringList GetStatusList(bool kick = true); + virtual QStringList GetStatusList(void) const; /// \brief Returns true iff scriptStatus.IsGood() and signalLock.IsGood() /// return true @@ -197,8 +196,6 @@ class SignalMonitor : protected QThread volatile uint64_t flags; int update_rate; uint minimum_update_rate; - bool running; - bool exit; bool update_done; bool notify_frontend; bool tablemon; @@ -215,6 +212,10 @@ class SignalMonitor : protected QThread vector listeners; QMutex startStopLock; + QWaitCondition startStopWait; // protected by startStopLock + volatile bool running; // protected by startStopLock + volatile bool exit; // protected by startStopLock + mutable QMutex statusLock; mutable QMutex listenerLock; };