MythTV  0.28pre
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Friends | List of all members
MThread Class Reference

This is a wrapper around QThread that does several additional things. More...

#include <mthread.h>

Inherited by AlbumArtScannerThread, AppleRemote, AudioOutputBase, AudioTestThread, CDEjectorThread, CDRipperThread, CDScannerThread, CECAdapter, ChildCountThread, CopyImageThread, DBLoggerThread, Decoder, DecoderThread, DeleteThread, DeviceReadBuffer [protected], ExpireThread, FetcherThread, FIFOThread, FileCopyThread, FileCopyThread, FileScannerThread, FilterScanThread, FirewireTableMonitorThread, GameScannerThread, GetRecordingListThread, GrabberDownloadThread, GrabberScript, HLSPlaylistWorker, HLSStreamWorker, HouseKeepingThread, ImageScanThread, JoystickMenuThread, KenBurnsImageLoader, LIRC, LogForwardThread, LoggerThread, LogServerThread, MetadataDownload, MetadataImageDownload, MonitorThread, MPoolThread, MythDownloadManager, MythSignalingTimer [private], MythSystemLegacyIOHandler, MythSystemLegacyIOHandler, MythSystemLegacyManager, MythSystemLegacyManager, MythSystemLegacySignalManager, MythSystemLegacySignalManager, NVRAudioThread, NVRWriteThread, PlaybackBoxHelper, PlaylistLoadingThread, PlaylistWorker, PreviewGenerator, PreviewGeneratorQueue, RingBuffer [protected], Scheduler, SignalMonitor [protected], SSDP, StreamHandler [protected], StreamWorker, TaskQueue, TFWSyncThread, TFWWriteThread, ThumbGenerator, TVBrowseHelper, UpdateThread, VBIThread, and VideoScannerThread.

Collaboration diagram for MThread:
Collaboration graph
[legend]

Public Member Functions

 MThread (const QString &objectName)
 Standard constructor. More...
 
 MThread (const QString &objectName, QRunnable *runnable)
 Use this constructor if you want the default run() method to run the QRunnable's run() method instead of entering the Qt event loop. More...
 
virtual ~MThread ()
 
void RunProlog (void)
 Sets up a thread, call this if you reimplement run(). More...
 
void RunEpilog (void)
 Cleans up a thread's resources, call this if you reimplement run(). More...
 
QThread * qthread (void)
 Returns the thread, this will always return the same pointer no matter how often you restart the thread. More...
 
void setObjectName (const QString &name)
 
QString objectName (void) const
 
void setPriority (QThread::Priority priority)
 
QThread::Priority priority (void) const
 
bool isFinished (void) const
 
bool isRunning (void) const
 
void setStackSize (uint stackSize)
 
uint stackSize (void) const
 
void exit (int retcode=0)
 Use this to exit from the thread if you are using a Qt event loop. More...
 
void start (QThread::Priority=QThread::InheritPriority)
 Tell MThread to start running the thread in the near future. More...
 
void terminate (void)
 Kill a thread unsafely. More...
 
void quit (void)
 calls exit(0) More...
 
bool wait (unsigned long time=ULONG_MAX)
 Wait for the MThread to exit, with a maximum timeout. More...
 

Static Public Member Functions

static void ThreadSetup (const QString &)
 This is to be called on startup in those few threads that haven't been ported to MThread. More...
 
static void ThreadCleanup (void)
 This is to be called on exit in those few threads that haven't been ported to MThread. More...
 
static void Cleanup (void)
 This will print out all the running threads, call exit(1) on each and then wait up to 5 seconds total for all the threads to exit. More...
 
static void GetAllThreadNames (QStringList &list)
 
static void GetAllRunningThreadNames (QStringList &list)
 

Static Public Attributes

static const int kDefaultStartTimeout
 

Protected Member Functions

virtual void run (void)
 Runs the Qt event loop unless we have a QRunnable, in which case we run the runnable run instead. More...
 
int exec (void)
 Enters the qt event loop. call exit or quit to exit thread. More...
 

Static Protected Member Functions

static void setTerminationEnabled (bool enabled=true)
 
static void sleep (unsigned long time)
 
static void msleep (unsigned long time)
 
static void usleep (unsigned long time)
 

Protected Attributes

MThreadInternalm_thread
 
QRunnable * m_runnable
 
bool m_prolog_executed
 
bool m_epilog_executed
 

Friends

class MThreadInternal
 

Detailed Description

This is a wrapper around QThread that does several additional things.

First it requires that you set the thread's name which is used for debugging.

It adds RunProlog() and RunEpilog() which are called automatically when you don't override run(), but must be called explicitly if you do. These take care of setting up logging and take care of dealing with QSqlConnections which are per-thread variables.

It also adds some sanity checking to the destructor so a thread can not be deleted while it still running.

Optionally it can be given a QRunnable to run in MThread::run() instead of calling QThread::run() (which starts an event loop.) When you override MThread::run() or use a QRunnable you are responsible for stopping the thread, MThread::exit() will not work.

Warning: Do not statically initialize MThreads. C++ itself doesn't allow you to specify the order of static initializations. See: http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.15

Definition at line 46 of file mthread.h.

Constructor & Destructor Documentation

MThread::MThread ( const QString &  objectName)
explicit

Standard constructor.

Definition at line 102 of file mthread.cpp.

MThread::MThread ( const QString &  objectName,
QRunnable *  runnable 
)
explicit

Use this constructor if you want the default run() method to run the QRunnable's run() method instead of entering the Qt event loop.

Unlike MThreadPool, MThread will not delete a runnable with the autoDelete property set.

Definition at line 111 of file mthread.cpp.

MThread::~MThread ( )
virtual

Definition at line 120 of file mthread.cpp.

Member Function Documentation

void MThread::RunProlog ( void  )

Sets up a thread, call this if you reimplement run().

Definition at line 203 of file mthread.cpp.

Referenced by HLSPlaylistWorker::run(), HLSStreamWorker::run(), PlaylistLoadingThread::run(), DeleteThread::run(), FIFOThread::run(), ImageScanThread::run(), TFWWriteThread::run(), avfDecoder::run(), FetcherThread::run(), MonitorThread::run(), FirewireTableMonitorThread::run(), CDScannerThread::run(), HLSStreamHandler::run(), MythSystemLegacyIOHandler::run(), FileScannerThread::run(), TFWSyncThread::run(), GameScannerThread::run(), CDEjectorThread::run(), MythSignalingTimer::run(), MythDownloadManager::run(), FilterScanThread::run(), LIRC::run(), GetRecordingListThread::run(), GrabberScript::run(), CdDecoder::run(), DVBStreamHandler::run(), MetadataDownload::run(), AppleRemote::run(), DeviceReadBuffer::run(), MythSystemLegacyManager::run(), PreviewGenerator::run(), FileCopyThread::run(), ExternalStreamHandler::run(), ThumbGenerator::run(), ASIStreamHandler::run(), VideoScannerThread::run(), CDRipperThread::run(), MythSystemLegacySignalManager::run(), VBIThread::run(), HDHRStreamHandler::run(), IPTVStreamHandler::run(), JoystickMenuThread::run(), MetadataImageDownload::run(), TaskQueue::run(), Scheduler::run(), SSDP::run(), TVBrowseHelper::run(), SignalMonitor::run(), run(), GrabberDownloadThread::run(), HouseKeepingThread::run(), AudioOutputBase::run(), LogServerThread::run(), KenBurnsImageLoader::run(), AudioTestThread::run(), RingBuffer::run(), LoggerThread::run(), LogForwardThread::run(), ChildCountThread::run(), DBLoggerThread::run(), StreamWorker::run(), PlaylistWorker::run(), and CopyImageThread::run().

void MThread::RunEpilog ( void  )

Cleans up a thread's resources, call this if you reimplement run().

Definition at line 216 of file mthread.cpp.

Referenced by HLSPlaylistWorker::run(), HLSStreamWorker::run(), PlaylistLoadingThread::run(), DeleteThread::run(), FIFOThread::run(), ImageScanThread::run(), TFWWriteThread::run(), avfDecoder::run(), FetcherThread::run(), MonitorThread::run(), FirewireTableMonitorThread::run(), CDScannerThread::run(), HLSStreamHandler::run(), MythSystemLegacyIOHandler::run(), FileScannerThread::run(), TFWSyncThread::run(), GameScannerThread::run(), CDEjectorThread::run(), MythSignalingTimer::run(), MythDownloadManager::run(), FilterScanThread::run(), LIRC::run(), GetRecordingListThread::run(), GrabberScript::run(), CdDecoder::run(), DVBStreamHandler::run(), MetadataDownload::run(), AppleRemote::run(), DeviceReadBuffer::run(), MythSystemLegacyManager::run(), PreviewGenerator::run(), FileCopyThread::run(), ExternalStreamHandler::run(), ThumbGenerator::run(), ASIStreamHandler::run(), VideoScannerThread::run(), CDRipperThread::run(), MythSystemLegacySignalManager::run(), VBIThread::run(), HDHRStreamHandler::run(), IPTVStreamHandler::run(), JoystickMenuThread::run(), MetadataImageDownload::run(), TaskQueue::run(), Scheduler::run(), SSDP::run(), TVBrowseHelper::run(), SignalMonitor::run(), run(), GrabberDownloadThread::run(), HouseKeepingThread::run(), AudioOutputBase::run(), LogServerThread::run(), KenBurnsImageLoader::run(), AudioTestThread::run(), RingBuffer::run(), LoggerThread::run(), LogForwardThread::run(), ChildCountThread::run(), DBLoggerThread::run(), StreamWorker::run(), PlaylistWorker::run(), and CopyImageThread::run().

QThread * MThread::qthread ( void  )
void MThread::setObjectName ( const QString &  name)
QString MThread::objectName ( void  ) const

Definition at line 251 of file mthread.cpp.

void MThread::setPriority ( QThread::Priority  priority)

Definition at line 256 of file mthread.cpp.

QThread::Priority MThread::priority ( void  ) const

Definition at line 261 of file mthread.cpp.

Referenced by DVBStreamHandler::CycleFiltersByPriority().

bool MThread::isFinished ( void  ) const
bool MThread::isRunning ( void  ) const
void MThread::setStackSize ( uint  stackSize)

Definition at line 276 of file mthread.cpp.

uint MThread::stackSize ( void  ) const

Definition at line 281 of file mthread.cpp.

void MThread::exit ( int  retcode = 0)
void MThread::start ( QThread::Priority  p = QThread::InheritPriority)

Tell MThread to start running the thread in the near future.

Definition at line 291 of file mthread.cpp.

Referenced by MetadataImageDownload::addDownloads(), MetadataDownload::addLookup(), MetadataImageDownload::addThumb(), AutoExpire::AutoExpire(), CECAdapter::CECAdapter(), ImportMusicDialog::copyFile(), CopyMarkedFiles(), MythRAOPDevice::Create(), MythAirplayServer::Create(), DatabaseLogger::DatabaseLogger(), MusicPlayer::decoderHandlerReady(), MythPlayer::DecoderStart(), EditAlbumartDialog::doCopyImageToTag(), VideoScanner::doScan(), GameScanner::doScan(), GrabberManager::doUpdate(), GLSingleView::EffectKenBurns(), EITScanner::EITScanner(), FIFOWriter::FIFOInit(), finish_mpg(), CdDecoder::getMetadata(), GetMythDownloadManager(), GetRecordingListThread::GetRecordingListThread(), TVRec::Init(), UPNPScanner::Instance(), isom_write_avcc(), JobQueue::JobQueue(), MythSystemLegacyUnix::JumpAbort(), MythSystemLegacyWindows::JumpAbort(), logServerStart(), logStart(), main(), MythSystemLegacyUnix::Manage(), MythSystemLegacyWindows::Manage(), MythMainWindow::MythMainWindow(), MythSocket::MythSocket(), MythSystemLegacyUnix::MythSystemLegacyUnix(), MythSystemLegacyWindows::MythSystemLegacyWindows(), NetworkControl::NetworkControl(), HLSReader::Open(), ThreadedFileWriter::Open(), DVDStream::OpenFile(), HLSRingBuffer::OpenFile(), LinuxFirewireDevice::OpenPort(), PlaybackBoxHelper::PlaybackBoxHelper(), MetadataDownload::prependLookup(), PreviewGeneratorQueue::PreviewGeneratorQueue(), GrabberDownloadThread::refreshAll(), MHIContext::Restart(), CDRipperThread::ripTrack(), NuppelVideoRecorder::run(), LogServerThread::run(), HLSRingBuffer::SanitizeStreams(), IPTVChannelFetcher::Scan(), Scheduler::Scheduler(), SSDP::SSDP(), DVBCam::Start(), MythSignalingTimer::start(), LIRC::start(), DeviceReadBuffer::Start(), SignalMonitor::Start(), StreamHandler::Start(), RingBuffer::Start(), Ripper::startEjectCD(), PrivateDecoderCrystalHD::StartFetcherThread(), MediaMonitorDarwin::StartMonitoring(), MediaMonitor::StartMonitoring(), AudioOutputBase::StartOutputThread(), RipStatus::startRip(), ImportMusicDialog::startScan(), Ripper::startScanCD(), ChannelScanSM::StartScanner(), ImageScan::StartSync(), HouseKeeper::StartThread(), TaskQueue::TaskQueue(), AudioTest::toggle(), AudioSetupWizard::toggleSpeakers(), MThreadPool::TryStartInternal(), TVRec::TuningNewRecorder(), TVBrowseHelper::TVBrowseHelper(), AutoExpire::Update(), GalleryFilterDialog::updateFilter(), VBIThread::VBIThread(), and MetadataFactory::VideoScan().

void MThread::terminate ( void  )

Kill a thread unsafely.

This should never be called on a thread while it holds a mutex or semaphore, since those locks will never be unlocked. Use the static setTerminationEnabled(true) to tell MThread when it is safe to terminate the thread and setTerminationEnabled(false) to tell it that termination is not safe again.

Definition at line 298 of file mthread.cpp.

void MThread::quit ( void  )

calls exit(0)

Definition at line 303 of file mthread.cpp.

Referenced by UPNPScanner::Instance(), LogServerThread::stop(), and MythSocket::~MythSocket().

void MThread::ThreadSetup ( const QString &  name)
static
void MThread::ThreadCleanup ( void  )
static

This is to be called on exit in those few threads that haven't been ported to MThread.

Definition at line 234 of file mthread.cpp.

Referenced by dfd_controller_thunk(), JobQueue::FlagCommercialsThread(), JobQueue::MetadataLookupThread(), MPEG2fixup::ReplexStart(), RunEpilog(), JobQueue::TranscodeThread(), and JobQueue::UserJobThread().

bool MThread::wait ( unsigned long  time = ULONG_MAX)

Wait for the MThread to exit, with a maximum timeout.

Parameters
timeMaximum time to wait for MThread to exit, in ms

Definition at line 308 of file mthread.cpp.

Referenced by HLSPlaylistWorker::Cancel(), HLSStreamWorker::Cancel(), StreamWorker::Cancel(), PlaylistWorker::Cancel(), PlaylistContainer::cleanOutThreads(), cleanup(), MythRAOPDevice::Cleanup(), MythAirplayServer::Cleanup(), LinuxFirewireDevice::ClosePort(), RipStatus::customEvent(), MythPlayer::DecoderEnd(), MusicPlayer::decoderHandlerReady(), MThreadPool::DeletePoolThreads(), IPTVChannelFetcher::GetChannels(), UPNPScanner::Instance(), NuppelVideoRecorder::KillChildren(), RingBuffer::KillReadAheadThread(), logServerStop(), logStop(), PlaylistWorker::PlaylistWorker(), MpegRecorder::run(), PlaylistWorker::run(), ShutdownMythSystemLegacy(), DeviceReadBuffer::Start(), StreamHandler::Start(), ChannelScanSM::StartScanner(), MythSignalingTimer::stop(), DVBCam::Stop(), FirewireSignalMonitor::Stop(), SignalMonitor::Stop(), DeviceReadBuffer::Stop(), IPTVChannelFetcher::Stop(), StreamHandler::Stop(), DecoderHandler::stop(), DatabaseLogger::stopDatabaseAccess(), MHIContext::StopEngine(), MediaMonitor::StopMonitoring(), AudioOutputBase::StopOutputThread(), V4LRecorder::StopRecording(), ChannelScanSM::StopScanner(), LIRC::TeardownAll(), EITScanner::TeardownAll(), PreviewGeneratorQueue::TeardownPreviewGeneratorQueue(), TVRec::TeardownRecorder(), AudioTest::toggle(), AudioSetupWizard::toggleSpeakers(), Scheduler::Wait(), TVBrowseHelper::Wait(), AudioSetupWizard::~AudioSetupWizard(), AudioTest::~AudioTest(), AudioTestThread::~AudioTestThread(), AutoExpire::~AutoExpire(), CDRipperThread::~CDRipperThread(), ChildCountThread::~ChildCountThread(), DBLoggerThread::~DBLoggerThread(), FIFOWriter::~FIFOWriter(), GameScanner::~GameScanner(), GrabberDownloadThread::~GrabberDownloadThread(), GrabberScript::~GrabberScript(), HouseKeeper::~HouseKeeper(), JobQueue::~JobQueue(), LogForwardThread::~LogForwardThread(), LoggerThread::~LoggerThread(), LogServerThread::~LogServerThread(), MetadataDownload::~MetadataDownload(), MetadataFactory::~MetadataFactory(), MetadataImageDownload::~MetadataImageDownload(), MonitorThread::~MonitorThread(), MythDownloadManager::~MythDownloadManager(), MythMainWindow::~MythMainWindow(), MythSignalingTimer::~MythSignalingTimer(), MythSocket::~MythSocket(), MythSystemLegacyIOHandler::~MythSystemLegacyIOHandler(), MythSystemLegacyManager::~MythSystemLegacyManager(), MythSystemLegacySignalManager::~MythSystemLegacySignalManager(), NetworkControl::~NetworkControl(), PlaybackBoxHelper::~PlaybackBoxHelper(), PlaylistContainer::~PlaylistContainer(), PreviewGenerator::~PreviewGenerator(), PreviewGeneratorQueue::~PreviewGeneratorQueue(), PrivateDecoderCrystalHD::~PrivateDecoderCrystalHD(), RingBuffer::~RingBuffer(), Scheduler::~Scheduler(), SignalMonitor::~SignalMonitor(), SSDP::~SSDP(), TaskQueue::~TaskQueue(), ThreadedFileWriter::~ThreadedFileWriter(), ThumbGenerator::~ThumbGenerator(), TVRec::~TVRec(), V4LRecorder::~V4LRecorder(), VBIThread::~VBIThread(), and VideoScanner::~VideoScanner().

void MThread::Cleanup ( void  )
static

This will print out all the running threads, call exit(1) on each and then wait up to 5 seconds total for all the threads to exit.

Definition at line 146 of file mthread.cpp.

Referenced by MythCoreContextPrivate::~MythCoreContextPrivate().

void MThread::GetAllThreadNames ( QStringList &  list)
static

Definition at line 184 of file mthread.cpp.

void MThread::GetAllRunningThreadNames ( QStringList &  list)
static

Definition at line 192 of file mthread.cpp.

void MThread::run ( void  )
protectedvirtual

Runs the Qt event loop unless we have a QRunnable, in which case we run the runnable run instead.

Note
If you override this method you must call RunProlog before you do any work and RunEpilog before you exit the run method.

Reimplemented in CopyImageThread, PlaylistWorker, StreamWorker, AlbumArtScannerThread, DBLoggerThread, ChildCountThread, LogForwardThread, LoggerThread, RingBuffer, AudioTestThread, KenBurnsImageLoader, LogServerThread, AudioOutputBase, HouseKeepingThread, GrabberDownloadThread, SignalMonitor, MPoolThread, TVBrowseHelper, DecoderThread, SSDP, Scheduler, MetadataImageDownload, TaskQueue, JoystickMenuThread, IPTVStreamHandler, HDHRStreamHandler, DeleteThread, VBIThread, MythSystemLegacySignalManager, MythSystemLegacySignalManager, CDRipperThread, VideoScannerThread, NVRAudioThread, ASIStreamHandler, ExternalStreamHandler, ThumbGenerator, PreviewGenerator, FileCopyThread, MythSystemLegacyManager, DeviceReadBuffer, AppleRemote, MythSystemLegacyManager, NVRWriteThread, UpdateThread, MetadataDownload, DVBStreamHandler, CdDecoder, ExpireThread, FileCopyThread, GrabberScript, GetRecordingListThread, LIRC, FilterScanThread, MythDownloadManager, MythSignalingTimer, CDEjectorThread, GameScannerThread, TFWSyncThread, MythSystemLegacyIOHandler, FileScannerThread, HLSStreamHandler, MythSystemLegacyIOHandler, FirewireTableMonitorThread, CDScannerThread, MonitorThread, FetcherThread, avfDecoder, TFWWriteThread, ImageScanThread, DeleteThread, FIFOThread, HLSStreamWorker, PlaylistLoadingThread, HLSPlaylistWorker, and MonitorThreadDarwin.

Definition at line 315 of file mthread.cpp.

int MThread::exec ( void  )
protected

Enters the qt event loop. call exit or quit to exit thread.

Definition at line 325 of file mthread.cpp.

Referenced by AppleRemote::run(), IPTVStreamHandler::run(), and LogServerThread::run().

void MThread::setTerminationEnabled ( bool  enabled = true)
staticprotected

Definition at line 330 of file mthread.cpp.

Referenced by RunProlog().

void MThread::sleep ( unsigned long  time)
staticprotected

Definition at line 335 of file mthread.cpp.

Referenced by ExternalStreamHandler::Close(), LIRC::run(), and Scheduler::run().

void MThread::msleep ( unsigned long  time)
staticprotected
void MThread::usleep ( unsigned long  time)
staticprotected

Friends And Related Function Documentation

friend class MThreadInternal
friend

Definition at line 48 of file mthread.h.

Member Data Documentation

const int MThread::kDefaultStartTimeout
static

Definition at line 114 of file mthread.h.

MThreadInternal* MThread::m_thread
protected
QRunnable* MThread::m_runnable
protected

Definition at line 131 of file mthread.h.

Referenced by run().

bool MThread::m_prolog_executed
protected

Definition at line 132 of file mthread.h.

Referenced by RunProlog(), start(), and ~MThread().

bool MThread::m_epilog_executed
protected

Definition at line 133 of file mthread.h.

Referenced by RunEpilog(), start(), and ~MThread().


The documentation for this class was generated from the following files: