Changed cThread Active() vs. Running()

This commit is contained in:
Klaus Schmidinger 2005-08-14 11:24:57 +02:00
parent 8fe90254f6
commit af54ce4842
11 changed files with 52 additions and 53 deletions

View File

@ -3672,12 +3672,11 @@ Video Disk Recorder Revision History
to Andreas Böttger). to Andreas Böttger).
- Fixed a memory leak in the SVDRP command LSTE (thanks to Stefan Huelswitt). - Fixed a memory leak in the SVDRP command LSTE (thanks to Stefan Huelswitt).
2005-08-13: Version 1.3.29 2005-08-14: Version 1.3.29
- Fixed a race condition in cTransfer (thanks to Klaus ??? for reporting this one). - Fixed a race condition in cTransfer (thanks to Klaus ??? for reporting this one).
In doing so, the 'active' variables used by the actual derived cThread classes In doing so, the 'active' variables used by the actual derived cThread classes
have been replaced by the cThread::Active() function. The previous functionality have been replaced by the cThread::Running() function.
of cThread::Active() has been moved into the new cThread::Running().
Plugin authors may want to check their derived cThread classes and replace any 'active' Plugin authors may want to check their derived cThread classes and replace any 'active'
variables the same way as, for instance, done in transfer.c. variables the same way as, for instance, done in transfer.c.
- Fixed handling EPG data for time shifted events (thanks to Marco Schlüßler). - Fixed handling EPG data for time shifted events (thanks to Marco Schlüßler).

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.9 2005/08/13 11:49:02 kls Exp $ * $Id: cutter.c 1.10 2005/08/14 10:51:54 kls Exp $
*/ */
#include "cutter.h" #include "cutter.h"
@ -76,7 +76,7 @@ void cCuttingThread::Action(void)
uchar buffer[MAXFRAMESIZE]; uchar buffer[MAXFRAMESIZE];
bool LastMark = false; bool LastMark = false;
bool cutIn = true; bool cutIn = true;
while (Active()) { while (Running()) {
uchar FileNumber; uchar FileNumber;
int FileOffset, Length; int FileOffset, Length;
uchar PictureType; uchar PictureType;
@ -213,7 +213,7 @@ bool cCutter::Start(const char *FileName)
void cCutter::Stop(void) void cCutter::Stop(void)
{ {
bool Interrupted = cuttingThread && cuttingThread->Running(); bool Interrupted = cuttingThread && cuttingThread->Active();
const char *Error = cuttingThread ? cuttingThread->Error() : NULL; const char *Error = cuttingThread ? cuttingThread->Error() : NULL;
delete cuttingThread; delete cuttingThread;
cuttingThread = NULL; cuttingThread = NULL;
@ -230,7 +230,7 @@ void cCutter::Stop(void)
bool cCutter::Active(void) bool cCutter::Active(void)
{ {
if (cuttingThread) { if (cuttingThread) {
if (cuttingThread->Running()) if (cuttingThread->Active())
return true; return true;
error = cuttingThread->Error(); error = cuttingThread->Error();
Stop(); Stop();

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.104 2005/08/13 11:44:06 kls Exp $ * $Id: device.c 1.105 2005/08/14 10:52:08 kls Exp $
*/ */
#include "device.h" #include "device.h"
@ -1124,8 +1124,8 @@ bool cDevice::Receiving(bool CheckAny) const
void cDevice::Action(void) void cDevice::Action(void)
{ {
if (Active() && OpenDvr()) { if (Running() && OpenDvr()) {
while (Active()) { while (Running()) {
// Read data from the DVR device: // Read data from the DVR device:
uchar *b = NULL; uchar *b = NULL;
if (GetTSPacket(b)) { if (GetTSPacket(b)) {
@ -1186,7 +1186,7 @@ bool cDevice::AttachReceiver(cReceiver *Receiver)
Receiver->device = this; Receiver->device = this;
receiver[i] = Receiver; receiver[i] = Receiver;
Unlock(); Unlock();
if (!Active()) if (!Running())
Start(); Start();
return true; return true;
} }
@ -1254,7 +1254,7 @@ void cTSBuffer::Action(void)
if (ringBuffer) { if (ringBuffer) {
bool firstRead = true; bool firstRead = true;
cPoller Poller(f); cPoller Poller(f);
while (Active()) { while (Running()) {
if (firstRead || Poller.Poll(100)) { if (firstRead || Poller.Poll(100)) {
firstRead = false; firstRead = false;
int r = ringBuffer->Read(f); int r = ringBuffer->Read(f);

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.132 2005/08/13 11:40:46 kls Exp $ * $Id: dvbdevice.c 1.133 2005/08/14 10:52:26 kls Exp $
*/ */
#include "dvbdevice.h" #include "dvbdevice.h"
@ -291,7 +291,7 @@ bool cDvbTuner::SetFrontend(void)
void cDvbTuner::Action(void) void cDvbTuner::Action(void)
{ {
dvb_frontend_event event; dvb_frontend_event event;
while (Active()) { while (Running()) {
Lock(); Lock();
if (tunerStatus == tsSet) { if (tunerStatus == tsSet) {
while (GetFrontendEvent(event)) while (GetFrontendEvent(event))

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.37 2005/08/13 12:27:17 kls Exp $ * $Id: dvbplayer.c 1.38 2005/08/14 10:52:45 kls Exp $
*/ */
#include "dvbplayer.h" #include "dvbplayer.h"
@ -144,7 +144,7 @@ int cNonBlockingFileReader::Read(int FileHandle, uchar *Buffer, int Length)
void cNonBlockingFileReader::Action(void) void cNonBlockingFileReader::Action(void)
{ {
while (Active()) { while (Running()) {
Lock(); Lock();
if (!hasData && f >= 0 && buffer) { if (!hasData && f >= 0 && buffer) {
int r = safe_read(f, buffer + length, wanted - length); int r = safe_read(f, buffer + length, wanted - length);
@ -201,7 +201,7 @@ protected:
public: public:
cDvbPlayer(const char *FileName); cDvbPlayer(const char *FileName);
virtual ~cDvbPlayer(); virtual ~cDvbPlayer();
bool Active(void) { return cThread::Active(); } bool Active(void) { return cThread::Running(); }
void Pause(void); void Pause(void);
void Play(void); void Play(void);
void Forward(void); void Forward(void);
@ -363,7 +363,7 @@ void cDvbPlayer::Action(void)
int Length = 0; int Length = 0;
bool Sleep = false; bool Sleep = false;
while (Active() && (NextFile() || readIndex >= 0 || ringBuffer->Available() || !DeviceFlush(100))) { while (Running() && (NextFile() || readIndex >= 0 || ringBuffer->Available() || !DeviceFlush(100))) {
if (Sleep) { if (Sleep) {
cCondWait::SleepMs(3); // this keeps the CPU load low cCondWait::SleepMs(3); // this keeps the CPU load low
Sleep = false; Sleep = 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: recorder.c 1.14 2005/08/13 11:33:35 kls Exp $ * $Id: recorder.c 1.15 2005/08/14 10:53:28 kls Exp $
*/ */
#include <stdarg.h> #include <stdarg.h>
@ -93,11 +93,11 @@ bool cFileWriter::NextFile(void)
void cFileWriter::Action(void) void cFileWriter::Action(void)
{ {
time_t t = time(NULL); time_t t = time(NULL);
while (Active()) { while (Running()) {
int Count; int Count;
uchar *p = remux->Get(Count, &pictureType); uchar *p = remux->Get(Count, &pictureType);
if (p) { if (p) {
if (!Active() && pictureType == I_FRAME) // finish the recording before the next 'I' frame if (!Running() && pictureType == I_FRAME) // finish the recording before the next 'I' frame
break; break;
if (NextFile()) { if (NextFile()) {
if (index && pictureType != NO_PICTURE) if (index && pictureType != NO_PICTURE)
@ -155,16 +155,16 @@ void cRecorder::Activate(bool On)
void cRecorder::Receive(uchar *Data, int Length) void cRecorder::Receive(uchar *Data, int Length)
{ {
if (Active()) { if (Running()) {
int p = ringBuffer->Put(Data, Length); int p = ringBuffer->Put(Data, Length);
if (p != Length && Active()) if (p != Length && Running())
ringBuffer->ReportOverflow(Length - p); ringBuffer->ReportOverflow(Length - p);
} }
} }
void cRecorder::Action(void) void cRecorder::Action(void)
{ {
while (Active()) { while (Running()) {
int r; int r;
uchar *b = ringBuffer->Get(r); uchar *b = ringBuffer->Get(r);
if (b) { if (b) {

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.43 2005/08/13 11:28:35 kls Exp $ * $Id: remote.c 1.44 2005/08/14 10:53:55 kls Exp $
*/ */
#include "remote.h" #include "remote.h"
@ -259,11 +259,11 @@ int cKbdRemote::MapCodeToFunc(uint64 Code)
void cKbdRemote::Action(void) void cKbdRemote::Action(void)
{ {
cPoller Poller(STDIN_FILENO); cPoller Poller(STDIN_FILENO);
while (Active()) { while (Running()) {
if (Poller.Poll(100)) { if (Poller.Poll(100)) {
uint64 Command = 0; uint64 Command = 0;
uint i = 0; uint i = 0;
while (Active() && i < sizeof(Command)) { while (Running() && i < sizeof(Command)) {
uchar ch; uchar ch;
int r = read(STDIN_FILENO, &ch, 1); int r = read(STDIN_FILENO, &ch, 1);
if (r == 1) { if (r == 1) {

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: sections.c 1.12 2005/08/13 11:25:04 kls Exp $ * $Id: sections.c 1.13 2005/08/14 10:54:39 kls Exp $
*/ */
#include "sections.h" #include "sections.h"
@ -165,7 +165,7 @@ void cSectionHandler::SetStatus(bool On)
void cSectionHandler::Action(void) void cSectionHandler::Action(void)
{ {
SetPriority(19); SetPriority(19);
while (Active()) { while (Running()) {
Lock(); Lock();
if (waitForLock) if (waitForLock)

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.c 1.44 2005/08/13 11:22:37 kls Exp $ * $Id: thread.c 1.45 2005/08/14 11:15:42 kls Exp $
*/ */
#include "thread.h" #include "thread.h"
@ -197,7 +197,7 @@ bool cThread::emergencyExitRequested = false;
cThread::cThread(const char *Description) cThread::cThread(const char *Description)
{ {
running = active = false; active = running = false;
childTid = 0; childTid = 0;
description = NULL; description = NULL;
SetDescription(Description); SetDescription(Description);
@ -234,31 +234,31 @@ void *cThread::StartThread(cThread *Thread)
Thread->Action(); Thread->Action();
if (Thread->description) if (Thread->description)
dsyslog("%s thread ended (pid=%d, tid=%ld)", Thread->description, getpid(), pthread_self()); dsyslog("%s thread ended (pid=%d, tid=%ld)", Thread->description, getpid(), pthread_self());
Thread->active = false;
Thread->running = false; Thread->running = false;
Thread->active = false;
return NULL; return NULL;
} }
bool cThread::Start(void) bool cThread::Start(void)
{ {
if (!running) { if (!active) {
running = active = true; active = running = true;
if (pthread_create(&childTid, NULL, (void *(*) (void *))&StartThread, (void *)this) == 0) { if (pthread_create(&childTid, NULL, (void *(*) (void *))&StartThread, (void *)this) == 0) {
pthread_detach(childTid); // auto-reap pthread_detach(childTid); // auto-reap
pthread_setschedparam(childTid, SCHED_RR, 0); pthread_setschedparam(childTid, SCHED_RR, 0);
} }
else { else {
LOG_ERROR; LOG_ERROR;
running = active = false; active = running = false;
return false; return false;
} }
} }
return true; return true;
} }
bool cThread::Running(void) bool cThread::Active(void)
{ {
if (running) { if (active) {
// //
// Single UNIX Spec v2 says: // Single UNIX Spec v2 says:
// //
@ -273,7 +273,7 @@ bool cThread::Running(void)
if (err != ESRCH) if (err != ESRCH)
LOG_ERROR; LOG_ERROR;
childTid = 0; childTid = 0;
running = active = false; active = running = false;
} }
else else
return true; return true;
@ -283,11 +283,11 @@ bool cThread::Running(void)
void cThread::Cancel(int WaitSeconds) void cThread::Cancel(int WaitSeconds)
{ {
active = false; running = false;
if (running) { if (active) {
if (WaitSeconds > 0) { if (WaitSeconds > 0) {
for (time_t t0 = time(NULL) + WaitSeconds; time(NULL) < t0; ) { for (time_t t0 = time(NULL) + WaitSeconds; time(NULL) < t0; ) {
if (!Running()) if (!Active())
return; return;
cCondWait::SleepMs(10); cCondWait::SleepMs(10);
} }
@ -295,7 +295,7 @@ void cThread::Cancel(int WaitSeconds)
} }
pthread_cancel(childTid); pthread_cancel(childTid);
childTid = 0; childTid = 0;
running = false; active = 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: thread.h 1.29 2005/08/13 13:01:33 kls Exp $ * $Id: thread.h 1.30 2005/08/14 11:21:48 kls Exp $
*/ */
#ifndef __THREAD_H #ifndef __THREAD_H
@ -75,8 +75,8 @@ public:
class cThread { class cThread {
friend class cThreadLock; friend class cThreadLock;
private: private:
bool running;
bool active; bool active;
bool running;
pthread_t childTid; pthread_t childTid;
cMutex mutex; cMutex mutex;
char *description; char *description;
@ -89,13 +89,13 @@ protected:
virtual void Action(void) = 0; virtual void Action(void) = 0;
///< A derived cThread class must implement the code it wants to ///< A derived cThread class must implement the code it wants to
///< execute as a separate thread in this function. If this is ///< execute as a separate thread in this function. If this is
///< a loop, it must check Active() repeatedly to see whether ///< a loop, it must check Running() repeatedly to see whether
///< it's time to stop. ///< it's time to stop.
bool Active(void) { return active; } bool Running(void) { return running; }
///< Returns false if a derived cThread object shall leave its Action() ///< Returns false if a derived cThread object shall leave its Action()
///< function. ///< function.
void Cancel(int WaitSeconds = 0); void Cancel(int WaitSeconds = 0);
///< Cancels the thread by first setting 'active' to false, so that ///< Cancels the thread by first setting 'running' to false, so that
///< the Action() loop can finish in an orderly fashion and then waiting ///< the Action() loop can finish in an orderly fashion and then waiting
///< up to WaitSeconds seconds for the thread to actually end. If the ///< up to WaitSeconds seconds for the thread to actually end. If the
///< thread doesn't end by itself, it is killed. ///< thread doesn't end by itself, it is killed.
@ -109,8 +109,8 @@ public:
void SetDescription(const char *Description, ...); void SetDescription(const char *Description, ...);
bool Start(void); bool Start(void);
///< Actually starts the thread. ///< Actually starts the thread.
bool Running(void); bool Active(void);
///< Checks whether the thread is actually running. ///< Checks whether the thread is still alive.
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.29 2005/08/13 11:19:46 kls Exp $ * $Id: transfer.c 1.30 2005/08/14 10:55:03 kls Exp $
*/ */
#include "transfer.h" #include "transfer.h"
@ -41,9 +41,9 @@ void cTransfer::Activate(bool On)
void cTransfer::Receive(uchar *Data, int Length) void cTransfer::Receive(uchar *Data, int Length)
{ {
if (IsAttached() && Active()) { if (IsAttached() && Running()) {
int p = ringBuffer->Put(Data, Length); int p = ringBuffer->Put(Data, Length);
if (p != Length && Active()) if (p != Length && Running())
ringBuffer->ReportOverflow(Length - p); ringBuffer->ReportOverflow(Length - p);
return; return;
} }
@ -65,7 +65,7 @@ void cTransfer::Action(void)
bool GotBufferReserve = false; bool GotBufferReserve = false;
int RequiredBufferReserve = KILOBYTE(DvbCardWith4MBofSDRAM ? 288 : 576); int RequiredBufferReserve = KILOBYTE(DvbCardWith4MBofSDRAM ? 288 : 576);
#endif #endif
while (Active()) { while (Running()) {
#ifdef FW_NEEDS_BUFFER_RESERVE_FOR_AC3 #ifdef FW_NEEDS_BUFFER_RESERVE_FOR_AC3
if (needsBufferReserve && !GotBufferReserve) { if (needsBufferReserve && !GotBufferReserve) {
//XXX For dolby we've to fill the buffer because the firmware does //XXX For dolby we've to fill the buffer because the firmware does