diff options
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) |