The cThread class now accepts a 'Description' parameter

This commit is contained in:
Klaus Schmidinger 2003-10-18 12:29:08 +02:00
parent 15816ee8e4
commit e53e43d2b8
13 changed files with 56 additions and 47 deletions

View File

@ -2438,3 +2438,10 @@ Video Disk Recorder Revision History
- Changed thread handling to make it work with NPTL ("Native Posix Thread Library"). - Changed thread handling to make it work with NPTL ("Native Posix Thread Library").
Thanks to Jon Burgess, Andreas Schultz, Werner Fink and Stefan Huelswitt. Thanks to Jon Burgess, Andreas Schultz, Werner Fink and Stefan Huelswitt.
- The cThread class now accepts a 'Description' parameter, which is used to log
the beginning and end of the thread, together with its process and thread id.
For descriptions that need additional parameters you can use the function
cThread::SetDescription(), which accepts 'printf()' like arguments.
Existing plugins that use threads should be changed to use this functionality
instead of explicit 'dsyslog()' calls inside their Action() function in order
to support logging the thread ids.

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: cutter.c 1.5 2003/08/17 09:04:04 kls Exp $ * $Id: cutter.c 1.6 2003/10/18 11:29:37 kls Exp $
*/ */
#include "cutter.h" #include "cutter.h"
@ -32,6 +32,7 @@ public:
}; };
cCuttingThread::cCuttingThread(const char *FromFileName, const char *ToFileName) cCuttingThread::cCuttingThread(const char *FromFileName, const char *ToFileName)
:cThread("video cutting")
{ {
error = NULL; error = NULL;
active = false; active = false;
@ -62,8 +63,6 @@ cCuttingThread::~cCuttingThread()
void cCuttingThread::Action(void) void cCuttingThread::Action(void)
{ {
dsyslog("video cutting thread started (pid=%d)", getpid());
cMark *Mark = fromMarks.First(); cMark *Mark = fromMarks.First();
if (Mark) { if (Mark) {
fromFile = fromFileName->Open(); fromFile = fromFileName->Open();
@ -175,7 +174,6 @@ void cCuttingThread::Action(void)
} }
else else
esyslog("no editing marks found!"); esyslog("no editing marks found!");
dsyslog("end video cutting thread");
} }
// --- cCutter --------------------------------------------------------------- // --- cCutter ---------------------------------------------------------------

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: device.c 1.47 2003/08/15 12:34:36 kls Exp $ * $Id: device.c 1.48 2003/10/18 12:19:39 kls Exp $
*/ */
#include "device.h" #include "device.h"
@ -36,6 +36,8 @@ cDevice::cDevice(void)
{ {
cardIndex = nextCardIndex++; cardIndex = nextCardIndex++;
SetDescription("receiver on device %d", CardIndex() + 1);
SetVideoFormat(Setup.VideoFormat); SetVideoFormat(Setup.VideoFormat);
active = false; active = false;
@ -665,8 +667,6 @@ bool cDevice::Receiving(bool CheckAny) const
void cDevice::Action(void) void cDevice::Action(void)
{ {
dsyslog("receiver thread started on device %d (pid=%d)", CardIndex() + 1, getpid());
if (OpenDvr()) { if (OpenDvr()) {
active = true; active = true;
for (; active;) { for (; active;) {
@ -689,8 +689,6 @@ void cDevice::Action(void)
} }
CloseDvr(); CloseDvr();
} }
dsyslog("receiver thread ended on device %d (pid=%d)", CardIndex() + 1, getpid());
} }
bool cDevice::OpenDvr(void) bool cDevice::OpenDvr(void)

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: dvbdevice.c 1.67 2003/10/17 15:36:13 kls Exp $ * $Id: dvbdevice.c 1.68 2003/10/18 12:20:38 kls Exp $
*/ */
#include "dvbdevice.h" #include "dvbdevice.h"
@ -100,6 +100,7 @@ cDvbTuner::cDvbTuner(int Fd_Frontend, int CardIndex, fe_type_t FrontendType, cCi
useCa = false; useCa = false;
tunerStatus = tsIdle; tunerStatus = tsIdle;
startTime = time(NULL); startTime = time(NULL);
SetDescription("tuner on device %d", cardIndex + 1);
Start(); Start();
} }
@ -247,7 +248,6 @@ bool cDvbTuner::SetFrontend(void)
void cDvbTuner::Action(void) void cDvbTuner::Action(void)
{ {
dsyslog("tuner thread started on device %d (pid=%d)", cardIndex + 1, getpid());
active = true; active = true;
while (active) { while (active) {
cMutexLock MutexLock(&mutex); cMutexLock MutexLock(&mutex);
@ -302,7 +302,6 @@ void cDvbTuner::Action(void)
// in the beginning we loop more often to let the CAM connection start up fast // in the beginning we loop more often to let the CAM connection start up fast
newSet.TimedWait(mutex, (ciHandler && (time(NULL) - startTime < 20)) ? 100 : 1000); newSet.TimedWait(mutex, (ciHandler && (time(NULL) - startTime < 20)) ? 100 : 1000);
} }
dsyslog("tuner thread ended on device %d (pid=%d)", cardIndex + 1, getpid());
} }
// --- cDvbDevice ------------------------------------------------------------ // --- cDvbDevice ------------------------------------------------------------

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: dvbplayer.c 1.22 2003/05/24 09:04:26 kls Exp $ * $Id: dvbplayer.c 1.23 2003/10/18 11:31:54 kls Exp $
*/ */
#include "dvbplayer.h" #include "dvbplayer.h"
@ -93,6 +93,7 @@ public:
}; };
cNonBlockingFileReader::cNonBlockingFileReader(void) cNonBlockingFileReader::cNonBlockingFileReader(void)
:cThread("non blocking file reader")
{ {
f = -1; f = -1;
buffer = NULL; buffer = NULL;
@ -146,7 +147,6 @@ int cNonBlockingFileReader::Read(int FileHandle, uchar *Buffer, int Length)
void cNonBlockingFileReader::Action(void) void cNonBlockingFileReader::Action(void)
{ {
dsyslog("non blocking file reader thread started (pid=%d)", getpid());
active = true; active = true;
while (active) { while (active) {
cMutexLock MutexLock(&mutex); cMutexLock MutexLock(&mutex);
@ -165,7 +165,6 @@ void cNonBlockingFileReader::Action(void)
} }
newSet.TimedWait(mutex, 1000); newSet.TimedWait(mutex, 1000);
} }
dsyslog("non blocking file reader thread ended (pid=%d)", getpid());
} }
// --- cDvbPlayer ------------------------------------------------------------ // --- cDvbPlayer ------------------------------------------------------------
@ -235,6 +234,7 @@ public:
int cDvbPlayer::Speeds[] = { 0, -2, -4, -8, 1, 2, 4, 12, 0 }; int cDvbPlayer::Speeds[] = { 0, -2, -4, -8, 1, 2, 4, 12, 0 };
cDvbPlayer::cDvbPlayer(const char *FileName) cDvbPlayer::cDvbPlayer(const char *FileName)
:cThread("dvbplayer")
{ {
nonBlockingFileReader = NULL; nonBlockingFileReader = NULL;
ringBuffer = NULL; ringBuffer = NULL;
@ -405,8 +405,6 @@ void cDvbPlayer::Activate(bool On)
void cDvbPlayer::Action(void) void cDvbPlayer::Action(void)
{ {
dsyslog("dvbplayer thread started (pid=%d)", getpid());
uchar *b = NULL; uchar *b = NULL;
uchar *p = NULL; uchar *p = NULL;
int pc = 0; int pc = 0;
@ -550,8 +548,6 @@ void cDvbPlayer::Action(void)
cNonBlockingFileReader *nbfr = nonBlockingFileReader; cNonBlockingFileReader *nbfr = nonBlockingFileReader;
nonBlockingFileReader = NULL; nonBlockingFileReader = NULL;
delete nbfr; delete nbfr;
dsyslog("dvbplayer thread ended (pid=%d)", getpid());
} }
void cDvbPlayer::Pause(void) void cDvbPlayer::Pause(void)

7
eit.c
View File

@ -16,7 +16,7 @@
* the Free Software Foundation; either version 2 of the License, or * * the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. * * (at your option) any later version. *
* * * *
* $Id: eit.c 1.80 2003/10/12 11:05:42 kls Exp $ * $Id: eit.c 1.81 2003/10/18 12:24:18 kls Exp $
***************************************************************************/ ***************************************************************************/
#include "eit.h" #include "eit.h"
@ -1075,6 +1075,7 @@ time_t cSIProcessor::lastDump = time(NULL);
/** */ /** */
cSIProcessor::cSIProcessor(const char *FileName) cSIProcessor::cSIProcessor(const char *FileName)
:cThread("EIT processing")
{ {
fileName = strdup(FileName); fileName = strdup(FileName);
masterSIProcessor = numSIProcessors == 0; // the first one becomes the 'master' masterSIProcessor = numSIProcessors == 0; // the first one becomes the 'master'
@ -1179,8 +1180,6 @@ information and let the classes corresponding
to the tables write their information to the disk */ to the tables write their information to the disk */
void cSIProcessor::Action() void cSIProcessor::Action()
{ {
dsyslog("EIT processing thread started (pid=%d)%s", getpid(), masterSIProcessor ? " - master" : "");
time_t lastCleanup = time(NULL); time_t lastCleanup = time(NULL);
time_t lastPmtScan = time(NULL); time_t lastPmtScan = time(NULL);
@ -1342,8 +1341,6 @@ void cSIProcessor::Action()
} }
} }
} }
dsyslog("EIT processing thread ended (pid=%d)%s", getpid(), masterSIProcessor ? " - master" : "");
} }
/** Add a filter with packet identifier pid and /** Add a filter with packet identifier pid and

5
lirc.c
View File

@ -6,7 +6,7 @@
* *
* LIRC support added by Carsten Koch <Carsten.Koch@icem.de> 2000-06-16. * LIRC support added by Carsten Koch <Carsten.Koch@icem.de> 2000-06-16.
* *
* $Id: lirc.c 1.6 2003/04/27 11:39:47 kls Exp $ * $Id: lirc.c 1.7 2003/10/18 11:34:02 kls Exp $
*/ */
#include "lirc.h" #include "lirc.h"
@ -20,6 +20,7 @@
cLircRemote::cLircRemote(char *DeviceName) cLircRemote::cLircRemote(char *DeviceName)
:cRemote("LIRC") :cRemote("LIRC")
,cThread("LIRC remote control")
{ {
struct sockaddr_un addr; struct sockaddr_un addr;
addr.sun_family = AF_UNIX; addr.sun_family = AF_UNIX;
@ -49,8 +50,6 @@ bool cLircRemote::Ready(void)
void cLircRemote::Action(void) void cLircRemote::Action(void)
{ {
dsyslog("LIRC remote control thread started (pid=%d)", getpid());
int FirstTime = 0; int FirstTime = 0;
int LastTime = 0; int LastTime = 0;
char buf[LIRC_BUFFER_SIZE]; char buf[LIRC_BUFFER_SIZE];

5
rcu.c
View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: rcu.c 1.5 2003/05/02 14:42:40 kls Exp $ * $Id: rcu.c 1.6 2003/10/18 11:34:30 kls Exp $
*/ */
#include "rcu.h" #include "rcu.h"
@ -18,6 +18,7 @@
cRcuRemote::cRcuRemote(char *DeviceName) cRcuRemote::cRcuRemote(char *DeviceName)
:cRemote("RCU") :cRemote("RCU")
,cThread("RCU remote control")
{ {
dp = 0; dp = 0;
mode = modeB; mode = modeB;
@ -92,8 +93,6 @@ void cRcuRemote::Action(void)
} buffer; } buffer;
#pragma pack() #pragma pack()
dsyslog("RCU remote control thread started (pid=%d)", getpid());
time_t LastCodeRefresh = 0; time_t LastCodeRefresh = 0;
int FirstTime = 0; int FirstTime = 0;
uint64 LastCommand = 0; uint64 LastCommand = 0;

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: recorder.c 1.7 2003/08/02 13:01:19 kls Exp $ * $Id: recorder.c 1.8 2003/10/18 11:35:02 kls Exp $
*/ */
#include <stdarg.h> #include <stdarg.h>
@ -25,6 +25,7 @@
cRecorder::cRecorder(const char *FileName, int Ca, int Priority, int VPid, int APid1, int APid2, int DPid1, int DPid2) cRecorder::cRecorder(const char *FileName, int Ca, int Priority, int VPid, int APid1, int APid2, int DPid1, int DPid2)
:cReceiver(Ca, Priority, 5, VPid, APid1, APid2, DPid1, DPid2) :cReceiver(Ca, Priority, 5, VPid, APid1, APid2, DPid1, DPid2)
,cThread("recording")
{ {
ringBuffer = NULL; ringBuffer = NULL;
remux = NULL; remux = NULL;
@ -106,8 +107,6 @@ void cRecorder::Receive(uchar *Data, int Length)
void cRecorder::Action(void) void cRecorder::Action(void)
{ {
dsyslog("recording thread started (pid=%d)", getpid());
time_t t = time(NULL); time_t t = time(NULL);
active = true; active = true;
while (active) { while (active) {
@ -143,6 +142,4 @@ void cRecorder::Action(void)
else else
usleep(1); // this keeps the CPU load low usleep(1); // this keeps the CPU load low
} }
dsyslog("recording thread ended (pid=%d)", getpid());
} }

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: remote.c 1.38 2003/05/02 10:49:50 kls Exp $ * $Id: remote.c 1.39 2003/10/18 11:35:32 kls Exp $
*/ */
#include "remote.h" #include "remote.h"
@ -197,6 +197,7 @@ bool cKbdRemote::rawMode = false;
cKbdRemote::cKbdRemote(void) cKbdRemote::cKbdRemote(void)
:cRemote("KBD") :cRemote("KBD")
,cThread("KBD remote control")
{ {
active = false; active = false;
tcgetattr(STDIN_FILENO, &savedTm); tcgetattr(STDIN_FILENO, &savedTm);
@ -245,7 +246,6 @@ int cKbdRemote::MapCodeToFunc(uint64 Code)
void cKbdRemote::Action(void) void cKbdRemote::Action(void)
{ {
dsyslog("KBD remote control thread started (pid=%d)", getpid());
cPoller Poller(STDIN_FILENO); cPoller Poller(STDIN_FILENO);
active = true; active = true;
while (active) { while (active) {
@ -285,5 +285,4 @@ void cKbdRemote::Action(void)
} }
} }
} }
dsyslog("KBD remote control thread ended (pid=%d)", getpid());
} }

View File

@ -4,12 +4,14 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: thread.c 1.26 2003/10/18 10:29:25 kls Exp $ * $Id: thread.c 1.27 2003/10/18 12:14:55 kls Exp $
*/ */
#include "thread.h" #include "thread.h"
#include <errno.h> #include <errno.h>
#include <malloc.h>
#include <signal.h> #include <signal.h>
#include <stdarg.h>
#include <sys/resource.h> #include <sys/resource.h>
#include <sys/time.h> #include <sys/time.h>
#include <sys/wait.h> #include <sys/wait.h>
@ -118,7 +120,7 @@ void cMutex::Unlock(void)
bool cThread::signalHandlerInstalled = false; bool cThread::signalHandlerInstalled = false;
bool cThread::emergencyExitRequested = false; bool cThread::emergencyExitRequested = false;
cThread::cThread(void) cThread::cThread(const char *Description)
{ {
if (!signalHandlerInstalled) { if (!signalHandlerInstalled) {
signal(SIGIO, SignalHandler); signal(SIGIO, SignalHandler);
@ -126,10 +128,25 @@ cThread::cThread(void)
} }
running = false; running = false;
parentTid = childTid = 0; parentTid = childTid = 0;
description = NULL;
SetDescription(Description);
} }
cThread::~cThread() cThread::~cThread()
{ {
free(description);
}
void cThread::SetDescription(const char *Description, ...)
{
free(description);
description = NULL;
if (Description) {
va_list ap;
va_start(ap, Description);
vasprintf(&description, Description, ap);
va_end(ap);
}
} }
void cThread::SignalHandler(int signum) void cThread::SignalHandler(int signum)
@ -140,7 +157,11 @@ void cThread::SignalHandler(int signum)
void *cThread::StartThread(cThread *Thread) void *cThread::StartThread(cThread *Thread)
{ {
Thread->childTid = pthread_self(); Thread->childTid = pthread_self();
if (Thread->description)
dsyslog("%s thread started (pid=%d, tid=%ld)", Thread->description, getpid(), Thread->childTid);
Thread->Action(); Thread->Action();
if (Thread->description)
dsyslog("%s thread ended (pid=%d, tid=%ld)", Thread->description, getpid(), Thread->childTid);
Thread->childTid = 0; Thread->childTid = 0;
return NULL; return NULL;
} }

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: thread.h 1.16 2003/10/18 10:29:25 kls Exp $ * $Id: thread.h 1.17 2003/10/18 12:13:10 kls Exp $
*/ */
#ifndef __THREAD_H #ifndef __THREAD_H
@ -47,6 +47,7 @@ private:
pthread_t parentTid, childTid; pthread_t parentTid, childTid;
cMutex mutex; cMutex mutex;
bool running; bool running;
char *description;
static bool emergencyExitRequested; static bool emergencyExitRequested;
static bool signalHandlerInstalled; static bool signalHandlerInstalled;
static void SignalHandler(int signum); static void SignalHandler(int signum);
@ -58,8 +59,9 @@ protected:
virtual void Action(void) = 0; virtual void Action(void) = 0;
void Cancel(int WaitSeconds = 0); void Cancel(int WaitSeconds = 0);
public: public:
cThread(void); cThread(const char *Description = NULL);
virtual ~cThread(); virtual ~cThread();
void SetDescription(const char *Description, ...);
bool Start(void); bool Start(void);
bool Active(void); bool Active(void);
static bool EmergencyExit(bool Request = false); static bool EmergencyExit(bool Request = false);

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: transfer.c 1.14 2003/08/31 12:19:16 kls Exp $ * $Id: transfer.c 1.15 2003/10/18 11:36:03 kls Exp $
*/ */
#include "transfer.h" #include "transfer.h"
@ -19,6 +19,7 @@
cTransfer::cTransfer(int VPid, int APid1, int APid2, int DPid1, int DPid2) cTransfer::cTransfer(int VPid, int APid1, int APid2, int DPid1, int DPid2)
:cReceiver(0, -1, 5, VPid, APid1, APid2, DPid1, DPid2) :cReceiver(0, -1, 5, VPid, APid1, APid2, DPid1, DPid2)
,cThread("transfer")
{ {
ringBuffer = new cRingBufferLinear(VIDEOBUFSIZE, TS_SIZE * 2, true); ringBuffer = new cRingBufferLinear(VIDEOBUFSIZE, TS_SIZE * 2, true);
remux = new cRemux(VPid, APid1, APid2, DPid1, DPid2); remux = new cRemux(VPid, APid1, APid2, DPid1, DPid2);
@ -66,8 +67,6 @@ void cTransfer::Receive(uchar *Data, int Length)
void cTransfer::Action(void) void cTransfer::Action(void)
{ {
dsyslog("transfer thread started (pid=%d)", getpid());
int PollTimeouts = 0; int PollTimeouts = 0;
active = true; active = true;
while (active) { while (active) {
@ -125,8 +124,6 @@ void cTransfer::Action(void)
else else
usleep(1); // this keeps the CPU load low usleep(1); // this keeps the CPU load low
} }
dsyslog("transfer thread ended (pid=%d)", getpid());
} }
void cTransfer::StripAudioPackets(uchar *b, int Length, uchar Except) void cTransfer::StripAudioPackets(uchar *b, int Length, uchar Except)