diff options
author | Klaus Schmidinger <vdr@tvdr.de> | 2004-10-24 10:34:20 +0200 |
---|---|---|
committer | Klaus Schmidinger <vdr@tvdr.de> | 2004-10-24 10:34:20 +0200 |
commit | 70e60380562fb25a7acce9b47c75842d60722dd0 (patch) | |
tree | 7cd5a91474795be92ace936e24678fb5f1e890f0 /thread.c | |
parent | 73fde7480a71c1f92d26c333bad06d12dd5019be (diff) | |
download | vdr-70e60380562fb25a7acce9b47c75842d60722dd0.tar.gz vdr-70e60380562fb25a7acce9b47c75842d60722dd0.tar.bz2 |
Added some checks when cancelling a thread and removed the usleep() in cThread::Start(); removed 'running' from cThread
Diffstat (limited to 'thread.c')
-rw-r--r-- | thread.c | 29 |
1 files changed, 15 insertions, 14 deletions
@@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: thread.c 1.33 2004/10/24 09:47:57 kls Exp $ + * $Id: thread.c 1.34 2004/10/24 10:27:47 kls Exp $ */ #include "thread.h" @@ -189,7 +189,6 @@ bool cThread::emergencyExitRequested = false; cThread::cThread(const char *Description) { - running = false; parentTid = childTid = 0; description = NULL; SetDescription(Description); @@ -226,13 +225,11 @@ void *cThread::StartThread(cThread *Thread) bool cThread::Start(void) { - if (!running) { - running = true; + if (!childTid) { parentTid = pthread_self(); pthread_create(&childTid, NULL, (void *(*) (void *))&StartThread, (void *)this); pthread_detach(childTid); // auto-reap pthread_setschedparam(childTid, SCHED_RR, 0); - usleep(10000); // otherwise calling Active() immediately after Start() causes a "pure virtual method called" error } return true; //XXX return value of pthread_create()??? } @@ -263,16 +260,20 @@ bool cThread::Active(void) void cThread::Cancel(int WaitSeconds) { - running = false; - if (WaitSeconds > 0) { - for (time_t t0 = time(NULL) + WaitSeconds; time(NULL) < t0; ) { - if (!Active()) - return; - usleep(10000); - } - esyslog("ERROR: thread %ld won't end (waited %d seconds) - cancelling it...", childTid, WaitSeconds); + if (childTid) { + if (WaitSeconds > 0) { + for (time_t t0 = time(NULL) + WaitSeconds; time(NULL) < t0; ) { + if (!Active()) + return; + usleep(10000); + } + esyslog("ERROR: thread %ld won't end (waited %d seconds) - cancelling it...", childTid, WaitSeconds); + } + if (childTid) { + pthread_cancel(childTid); + childTid = 0; + } } - pthread_cancel(childTid); } bool cThread::EmergencyExit(bool Request) |