1
0
mirror of https://github.com/VDR4Arch/vdr.git synced 2023-10-10 13:36:52 +02:00

Added some checks when cancelling a thread and removed the usleep() in cThread::Start(); removed 'running' from cThread

This commit is contained in:
Klaus Schmidinger 2004-10-24 10:34:20 +02:00
parent 73fde7480a
commit 70e6038056
4 changed files with 22 additions and 16 deletions

View File

@ -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'

View File

@ -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.

View File

@ -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)

View File

@ -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);