vdr  2.2.0
Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
cThread Class Referenceabstract

#include <thread.h>

Public Member Functions

 cThread (const char *Description=NULL, bool LowPriority=false)
 
virtual ~cThread ()
 
void SetDescription (const char *Description,...) __attribute__((format(printf
 
void bool Start (void)
 
bool Active (void)
 

Static Public Member Functions

static tThreadId ThreadId (void)
 
static tThreadId IsMainThread (void)
 
static void SetMainThreadId (void)
 

Protected Member Functions

void SetPriority (int Priority)
 
void SetIOPriority (int Priority)
 
void Lock (void)
 
void Unlock (void)
 
virtual void Action (void)=0
 
bool Running (void)
 
void Cancel (int WaitSeconds=0)
 

Static Private Member Functions

static void * StartThread (cThread *Thread)
 

Private Attributes

bool active
 
bool running
 
pthread_t childTid
 
tThreadId childThreadId
 
cMutex mutex
 
char * description
 
bool lowPriority
 

Static Private Attributes

static tThreadId mainThreadId = 0
 

Friends

class cThreadLock
 

Detailed Description

Definition at line 77 of file thread.h.

Constructor & Destructor Documentation

cThread::cThread ( const char *  Description = NULL,
bool  LowPriority = false 
)

Creates a new thread.

If Description is present, a log file entry will be made when the thread starts and stops (see SetDescription()). The Start() function must be called to actually start the thread. LowPriority can be set to true to make this thread run at a lower priority.

Definition at line 207 of file thread.c.

cThread::~cThread ( )
virtual

Definition at line 218 of file thread.c.

Member Function Documentation

virtual void cThread::Action ( void  )
protectedpure virtual

A derived cThread class must implement the code it wants to execute as a separate thread in this function.

If this is a loop, it must check Running() repeatedly to see whether it's time to stop.

Implemented in cIndexFileGenerator, cDirCopier, cEpgDataWriter, cTSBuffer, cDevice, cDvbTuner, cCuttingThread, cDvbPlayer, cRecordings, cEpgDataReader, cTrueColorDemo, cKbdRemote, cNonBlockingFileReader, cCiAdapter, cRemoveDeletedRecordingsThread, cDvbSubtitleConverter, cRcuRemote, cRecorder, cSectionHandler, and cLircRemote.

Referenced by StartThread().

bool cThread::Active ( void  )
void cThread::Cancel ( int  WaitSeconds = 0)
protected

Cancels the thread by first setting 'running' to false, so that the Action() loop can finish in an orderly fashion and then waiting up to WaitSeconds seconds for the thread to actually end.

If the thread doesn't end by itself, it is killed. If WaitSeconds is -1, only 'running' is set to false and Cancel() returns immediately, without killing the thread.

Definition at line 323 of file thread.c.

References esyslog, and cCondWait::SleepMs().

Referenced by cRecorder::Activate(), cDvbPlayer::Activate(), cDevice::Detach(), cDirCopier::Stop(), cCiAdapter::~cCiAdapter(), cCuttingThread::~cCuttingThread(), cDvbCiAdapter::~cDvbCiAdapter(), cDvbSubtitleConverter::~cDvbSubtitleConverter(), cIndexFileGenerator::~cIndexFileGenerator(), cKbdRemote::~cKbdRemote(), cLircRemote::~cLircRemote(), cNonBlockingFileReader::~cNonBlockingFileReader(), cRcuRemote::~cRcuRemote(), cRecordings::~cRecordings(), cSectionHandler::~cSectionHandler(), and cTSBuffer::~cTSBuffer().

static tThreadId cThread::IsMainThread ( void  )
inlinestatic
void cThread::Lock ( void  )
inlineprotected
bool cThread::Running ( void  )
inlineprotected
void cThread::SetDescription ( const char *  Description,
  ... 
)
void cThread::SetIOPriority ( int  Priority)
protected

Definition at line 230 of file thread.c.

References LOG_ERROR.

Referenced by StartThread().

void cThread::SetMainThreadId ( void  )
static

Definition at line 346 of file thread.c.

References esyslog.

Referenced by main().

void cThread::SetPriority ( int  Priority)
protected

Definition at line 224 of file thread.c.

References LOG_ERROR.

Referenced by StartThread().

bool cThread::Start ( void  )

Sets the description of this thread, which will be used when logging starting or stopping of the thread.

Make sure any important information is within the first 15 characters of Description, because only these may be displayed in thread listings (like 'htop', for instance). Actually starts the thread. If the thread is already running, nothing happens.

Definition at line 273 of file thread.c.

References cTimeMs::Elapsed(), LOG_ERROR, cCondWait::SleepMs(), THREAD_STOP_SLEEP, and THREAD_STOP_TIMEOUT.

Referenced by cRecorder::Activate(), cDvbPlayer::Activate(), cDevice::AttachReceiver(), cCuttingThread::cCuttingThread(), cDvbCiAdapter::cDvbCiAdapter(), cDvbSubtitleConverter::cDvbSubtitleConverter(), cIndexFileGenerator::cIndexFileGenerator(), cKbdRemote::cKbdRemote(), cSchedules::Cleanup(), cLircRemote::cLircRemote(), cNonBlockingFileReader::cNonBlockingFileReader(), cRcuRemote::cRcuRemote(), cSectionHandler::cSectionHandler(), cTSBuffer::cTSBuffer(), cPluginRcu::Description(), cRecording::IsPesRecording(), main(), cDevice::PlayPesPacket(), RemoveDeletedRecordings(), cRecording::SetStartTime(), and cRecordings::Update().

void * cThread::StartThread ( cThread Thread)
staticprivate
tThreadId cThread::ThreadId ( void  )
static
void cThread::Unlock ( void  )
inlineprotected

Friends And Related Function Documentation

friend class cThreadLock
friend

Definition at line 78 of file thread.h.

Member Data Documentation

bool cThread::active
private

Definition at line 80 of file thread.h.

Referenced by StartThread().

tThreadId cThread::childThreadId
private

Definition at line 83 of file thread.h.

Referenced by StartThread().

pthread_t cThread::childTid
private

Definition at line 82 of file thread.h.

char* cThread::description
private

Definition at line 85 of file thread.h.

Referenced by cDevice::ClrAvailableTracks(), cDevice::SetAvailableTrack(), and StartThread().

bool cThread::lowPriority
private

Definition at line 86 of file thread.h.

Referenced by StartThread().

tThreadId cThread::mainThreadId = 0
staticprivate

Definition at line 87 of file thread.h.

Referenced by cMutex::Unlock().

cMutex cThread::mutex
private
bool cThread::running
private

Definition at line 81 of file thread.h.

Referenced by StartThread().


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