1
0
mirror of https://github.com/VDR4Arch/vdr.git synced 2023-10-10 13:36:52 +02:00

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").
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
* 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"
@ -32,6 +32,7 @@ public:
};
cCuttingThread::cCuttingThread(const char *FromFileName, const char *ToFileName)
:cThread("video cutting")
{
error = NULL;
active = false;
@ -62,8 +63,6 @@ cCuttingThread::~cCuttingThread()
void cCuttingThread::Action(void)
{
dsyslog("video cutting thread started (pid=%d)", getpid());
cMark *Mark = fromMarks.First();
if (Mark) {
fromFile = fromFileName->Open();
@ -175,7 +174,6 @@ void cCuttingThread::Action(void)
}
else
esyslog("no editing marks found!");
dsyslog("end video cutting thread");
}
// --- cCutter ---------------------------------------------------------------

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* 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"
@ -36,6 +36,8 @@ cDevice::cDevice(void)
{
cardIndex = nextCardIndex++;
SetDescription("receiver on device %d", CardIndex() + 1);
SetVideoFormat(Setup.VideoFormat);
active = false;
@ -665,8 +667,6 @@ bool cDevice::Receiving(bool CheckAny) const
void cDevice::Action(void)
{
dsyslog("receiver thread started on device %d (pid=%d)", CardIndex() + 1, getpid());
if (OpenDvr()) {
active = true;
for (; active;) {
@ -689,8 +689,6 @@ void cDevice::Action(void)
}
CloseDvr();
}
dsyslog("receiver thread ended on device %d (pid=%d)", CardIndex() + 1, getpid());
}
bool cDevice::OpenDvr(void)

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* 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"
@ -100,6 +100,7 @@ cDvbTuner::cDvbTuner(int Fd_Frontend, int CardIndex, fe_type_t FrontendType, cCi
useCa = false;
tunerStatus = tsIdle;
startTime = time(NULL);
SetDescription("tuner on device %d", cardIndex + 1);
Start();
}
@ -247,7 +248,6 @@ bool cDvbTuner::SetFrontend(void)
void cDvbTuner::Action(void)
{
dsyslog("tuner thread started on device %d (pid=%d)", cardIndex + 1, getpid());
active = true;
while (active) {
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
newSet.TimedWait(mutex, (ciHandler && (time(NULL) - startTime < 20)) ? 100 : 1000);
}
dsyslog("tuner thread ended on device %d (pid=%d)", cardIndex + 1, getpid());
}
// --- cDvbDevice ------------------------------------------------------------

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* 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"
@ -93,6 +93,7 @@ public:
};
cNonBlockingFileReader::cNonBlockingFileReader(void)
:cThread("non blocking file reader")
{
f = -1;
buffer = NULL;
@ -146,7 +147,6 @@ int cNonBlockingFileReader::Read(int FileHandle, uchar *Buffer, int Length)
void cNonBlockingFileReader::Action(void)
{
dsyslog("non blocking file reader thread started (pid=%d)", getpid());
active = true;
while (active) {
cMutexLock MutexLock(&mutex);
@ -165,7 +165,6 @@ void cNonBlockingFileReader::Action(void)
}
newSet.TimedWait(mutex, 1000);
}
dsyslog("non blocking file reader thread ended (pid=%d)", getpid());
}
// --- cDvbPlayer ------------------------------------------------------------
@ -235,6 +234,7 @@ public:
int cDvbPlayer::Speeds[] = { 0, -2, -4, -8, 1, 2, 4, 12, 0 };
cDvbPlayer::cDvbPlayer(const char *FileName)
:cThread("dvbplayer")
{
nonBlockingFileReader = NULL;
ringBuffer = NULL;
@ -405,8 +405,6 @@ void cDvbPlayer::Activate(bool On)
void cDvbPlayer::Action(void)
{
dsyslog("dvbplayer thread started (pid=%d)", getpid());
uchar *b = NULL;
uchar *p = NULL;
int pc = 0;
@ -550,8 +548,6 @@ void cDvbPlayer::Action(void)
cNonBlockingFileReader *nbfr = nonBlockingFileReader;
nonBlockingFileReader = NULL;
delete nbfr;
dsyslog("dvbplayer thread ended (pid=%d)", getpid());
}
void cDvbPlayer::Pause(void)

7
eit.c
View File

@ -16,7 +16,7 @@
* the Free Software Foundation; either version 2 of the License, or *
* (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"
@ -1075,6 +1075,7 @@ time_t cSIProcessor::lastDump = time(NULL);
/** */
cSIProcessor::cSIProcessor(const char *FileName)
:cThread("EIT processing")
{
fileName = strdup(FileName);
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 */
void cSIProcessor::Action()
{
dsyslog("EIT processing thread started (pid=%d)%s", getpid(), masterSIProcessor ? " - master" : "");
time_t lastCleanup = 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

5
lirc.c
View File

@ -6,7 +6,7 @@
*
* 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"
@ -20,6 +20,7 @@
cLircRemote::cLircRemote(char *DeviceName)
:cRemote("LIRC")
,cThread("LIRC remote control")
{
struct sockaddr_un addr;
addr.sun_family = AF_UNIX;
@ -49,8 +50,6 @@ bool cLircRemote::Ready(void)
void cLircRemote::Action(void)
{
dsyslog("LIRC remote control thread started (pid=%d)", getpid());
int FirstTime = 0;
int LastTime = 0;
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
* 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"
@ -18,6 +18,7 @@
cRcuRemote::cRcuRemote(char *DeviceName)
:cRemote("RCU")
,cThread("RCU remote control")
{
dp = 0;
mode = modeB;
@ -92,8 +93,6 @@ void cRcuRemote::Action(void)
} buffer;
#pragma pack()
dsyslog("RCU remote control thread started (pid=%d)", getpid());
time_t LastCodeRefresh = 0;
int FirstTime = 0;
uint64 LastCommand = 0;

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* 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>
@ -25,6 +25,7 @@
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)
,cThread("recording")
{
ringBuffer = NULL;
remux = NULL;
@ -106,8 +107,6 @@ void cRecorder::Receive(uchar *Data, int Length)
void cRecorder::Action(void)
{
dsyslog("recording thread started (pid=%d)", getpid());
time_t t = time(NULL);
active = true;
while (active) {
@ -143,6 +142,4 @@ void cRecorder::Action(void)
else
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
* 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"
@ -197,6 +197,7 @@ bool cKbdRemote::rawMode = false;
cKbdRemote::cKbdRemote(void)
:cRemote("KBD")
,cThread("KBD remote control")
{
active = false;
tcgetattr(STDIN_FILENO, &savedTm);
@ -245,7 +246,6 @@ int cKbdRemote::MapCodeToFunc(uint64 Code)
void cKbdRemote::Action(void)
{
dsyslog("KBD remote control thread started (pid=%d)", getpid());
cPoller Poller(STDIN_FILENO);
active = true;
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
* 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 <errno.h>
#include <malloc.h>
#include <signal.h>
#include <stdarg.h>
#include <sys/resource.h>
#include <sys/time.h>
#include <sys/wait.h>
@ -118,7 +120,7 @@ void cMutex::Unlock(void)
bool cThread::signalHandlerInstalled = false;
bool cThread::emergencyExitRequested = false;
cThread::cThread(void)
cThread::cThread(const char *Description)
{
if (!signalHandlerInstalled) {
signal(SIGIO, SignalHandler);
@ -126,10 +128,25 @@ cThread::cThread(void)
}
running = false;
parentTid = childTid = 0;
description = NULL;
SetDescription(Description);
}
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)
@ -140,7 +157,11 @@ void cThread::SignalHandler(int signum)
void *cThread::StartThread(cThread *Thread)
{
Thread->childTid = pthread_self();
if (Thread->description)
dsyslog("%s thread started (pid=%d, tid=%ld)", Thread->description, getpid(), Thread->childTid);
Thread->Action();
if (Thread->description)
dsyslog("%s thread ended (pid=%d, tid=%ld)", Thread->description, getpid(), Thread->childTid);
Thread->childTid = 0;
return NULL;
}

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* 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
@ -47,6 +47,7 @@ private:
pthread_t parentTid, childTid;
cMutex mutex;
bool running;
char *description;
static bool emergencyExitRequested;
static bool signalHandlerInstalled;
static void SignalHandler(int signum);
@ -58,8 +59,9 @@ protected:
virtual void Action(void) = 0;
void Cancel(int WaitSeconds = 0);
public:
cThread(void);
cThread(const char *Description = NULL);
virtual ~cThread();
void SetDescription(const char *Description, ...);
bool Start(void);
bool Active(void);
static bool EmergencyExit(bool Request = false);

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* 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"
@ -19,6 +19,7 @@
cTransfer::cTransfer(int VPid, int APid1, int APid2, int DPid1, int DPid2)
:cReceiver(0, -1, 5, VPid, APid1, APid2, DPid1, DPid2)
,cThread("transfer")
{
ringBuffer = new cRingBufferLinear(VIDEOBUFSIZE, TS_SIZE * 2, true);
remux = new cRemux(VPid, APid1, APid2, DPid1, DPid2);
@ -66,8 +67,6 @@ void cTransfer::Receive(uchar *Data, int Length)
void cTransfer::Action(void)
{
dsyslog("transfer thread started (pid=%d)", getpid());
int PollTimeouts = 0;
active = true;
while (active) {
@ -125,8 +124,6 @@ void cTransfer::Action(void)
else
usleep(1); // this keeps the CPU load low
}
dsyslog("transfer thread ended (pid=%d)", getpid());
}
void cTransfer::StripAudioPackets(uchar *b, int Length, uchar Except)