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 | |
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
-rw-r--r-- | CONTRIBUTORS | 2 | ||||
-rw-r--r-- | HISTORY | 4 | ||||
-rw-r--r-- | thread.c | 29 | ||||
-rw-r--r-- | thread.h | 3 |
4 files changed, 22 insertions, 16 deletions
diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 4e05f37c..a7e0d386 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -742,6 +742,8 @@ Ludwig Nussel <ludwig.nussel@web.de> for reporting a problem on systems that have UTF-8 enabled for pointing out a flaw in the the description of cRingBufferLinear for reporting a bug in cRingBufferLinear::Get() in case the buffer wraps around + for adding some checks when cancelling a thread and removing the usleep() in + cThread::Start() Thomas Koch <tom@harhar.net> for his support in keeping the Premiere World channels up to date in 'channels.conf' @@ -3065,3 +3065,7 @@ Video Disk Recorder Revision History small packet. - Removed the signal handler and WakeUp() call from cThread (it is no longer needed). +- Added some checks when cancelling a thread and removed the usleep() in + cThread::Start() (suggested by Ludwig Nussel). Also removed 'running' from + cThread and using only childTid to indicate whether a thread is actually + running. @@ -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) @@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: thread.h 1.22 2004/10/24 09:46:36 kls Exp $ + * $Id: thread.h 1.23 2004/10/24 10:28:48 kls Exp $ */ #ifndef __THREAD_H @@ -71,7 +71,6 @@ class cThread { private: pthread_t parentTid, childTid; cMutex mutex; - bool running; char *description; static bool emergencyExitRequested; static void *StartThread(cThread *Thread); |