summaryrefslogtreecommitdiff
path: root/thread.c
diff options
context:
space:
mode:
authorKlaus Schmidinger <vdr@tvdr.de>2005-08-13 13:17:24 +0200
committerKlaus Schmidinger <vdr@tvdr.de>2005-08-13 13:17:24 +0200
commitccb0add798961ce2fa24f625a00106cb0d3df709 (patch)
tree43e50aa8938a53236d90e260700e83296b26987d /thread.c
parent1921c7465fd72d8507b11230729754a17761c7e1 (diff)
downloadvdr-ccb0add798961ce2fa24f625a00106cb0d3df709.tar.gz
vdr-ccb0add798961ce2fa24f625a00106cb0d3df709.tar.bz2
Centralized 'thread active' handling
Diffstat (limited to 'thread.c')
-rw-r--r--thread.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/thread.c b/thread.c
index 9ac1b7ef..2944678c 100644
--- a/thread.c
+++ b/thread.c
@@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
- * $Id: thread.c 1.43 2005/05/29 11:40:30 kls Exp $
+ * $Id: thread.c 1.44 2005/08/13 11:22:37 kls Exp $
*/
#include "thread.h"
@@ -197,7 +197,7 @@ bool cThread::emergencyExitRequested = false;
cThread::cThread(const char *Description)
{
- running = false;
+ running = active = false;
childTid = 0;
description = NULL;
SetDescription(Description);
@@ -205,6 +205,7 @@ cThread::cThread(const char *Description)
cThread::~cThread()
{
+ Cancel(); // just in case the derived class didn't call it
free(description);
}
@@ -233,6 +234,7 @@ void *cThread::StartThread(cThread *Thread)
Thread->Action();
if (Thread->description)
dsyslog("%s thread ended (pid=%d, tid=%ld)", Thread->description, getpid(), pthread_self());
+ Thread->active = false;
Thread->running = false;
return NULL;
}
@@ -240,21 +242,21 @@ void *cThread::StartThread(cThread *Thread)
bool cThread::Start(void)
{
if (!running) {
- running = true;
+ running = active = true;
if (pthread_create(&childTid, NULL, (void *(*) (void *))&StartThread, (void *)this) == 0) {
pthread_detach(childTid); // auto-reap
pthread_setschedparam(childTid, SCHED_RR, 0);
}
else {
LOG_ERROR;
- running = false;
+ running = active = false;
return false;
}
}
return true;
}
-bool cThread::Active(void)
+bool cThread::Running(void)
{
if (running) {
//
@@ -271,7 +273,7 @@ bool cThread::Active(void)
if (err != ESRCH)
LOG_ERROR;
childTid = 0;
- running = false;
+ running = active = false;
}
else
return true;
@@ -281,10 +283,11 @@ bool cThread::Active(void)
void cThread::Cancel(int WaitSeconds)
{
+ active = false;
if (running) {
if (WaitSeconds > 0) {
for (time_t t0 = time(NULL) + WaitSeconds; time(NULL) < t0; ) {
- if (!Active())
+ if (!Running())
return;
cCondWait::SleepMs(10);
}