Some more changes to the 'childTid' handling in cThread

This commit is contained in:
Klaus Schmidinger 2004-11-26 14:05:36 +01:00
parent 4146ac1928
commit eb8405695b
3 changed files with 13 additions and 7 deletions

View File

@ -3160,7 +3160,9 @@ Video Disk Recorder Revision History
right day of week for timers in the future. right day of week for timers in the future.
- Some improvements to cPoller (thanks to Marco Schlüßler). - Some improvements to cPoller (thanks to Marco Schlüßler).
2004-11-22: Version 1.3.18 2004-11-26: Version 1.3.18
- Removed an unused variable from cTimer::GetWDayFromMDay() (thanks to Wayne Keer - Removed an unused variable from cTimer::GetWDayFromMDay() (thanks to Wayne Keer
for reporting this one). for reporting this one).
- Some more changes to the 'childTid' handling in cThread (based on suggestions by
Stefan Huelswitt).

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: thread.c 1.37 2004/11/20 16:21:14 kls Exp $ * $Id: thread.c 1.38 2004/11/26 13:50:37 kls Exp $
*/ */
#include "thread.h" #include "thread.h"
@ -221,19 +221,22 @@ void cThread::SetDescription(const char *Description, ...)
void *cThread::StartThread(cThread *Thread) void *cThread::StartThread(cThread *Thread)
{ {
Thread->childTidMutex.Lock();
Thread->childTid = pthread_self(); Thread->childTid = pthread_self();
Thread->childTidMutex.Unlock();
if (Thread->description) if (Thread->description)
dsyslog("%s thread started (pid=%d, tid=%ld)", Thread->description, getpid(), Thread->childTid); dsyslog("%s thread started (pid=%d, tid=%ld)", Thread->description, getpid(), Thread->childTid);
Thread->Action(); Thread->Action();
if (Thread->description) if (Thread->description)
dsyslog("%s thread ended (pid=%d, tid=%ld)", Thread->description, getpid(), Thread->childTid); dsyslog("%s thread ended (pid=%d, tid=%ld)", Thread->description, getpid(), Thread->childTid);
Thread->childTidMutex.Lock();
Thread->childTid = 0; Thread->childTid = 0;
Thread->childTidMutex.Unlock();
return NULL; return NULL;
} }
bool cThread::Start(void) bool cThread::Start(void)
{ {
Lock();
if (!childTid) { if (!childTid) {
parentTid = pthread_self(); parentTid = pthread_self();
pthread_t Tid; pthread_t Tid;
@ -241,7 +244,6 @@ bool cThread::Start(void)
pthread_detach(Tid); // auto-reap pthread_detach(Tid); // auto-reap
pthread_setschedparam(Tid, SCHED_RR, 0); pthread_setschedparam(Tid, SCHED_RR, 0);
} }
Unlock();
return true; //XXX return value of pthread_create()??? return true; //XXX return value of pthread_create()???
} }
@ -257,6 +259,7 @@ bool cThread::Active(void)
// As in kill(), if sig is zero, error checking is // As in kill(), if sig is zero, error checking is
// performed but no signal is actually sent. // performed but no signal is actually sent.
// //
cMutexLock MutexLock(&childTidMutex);
int err; int err;
if ((err = pthread_kill(childTid, 0)) != 0) { if ((err = pthread_kill(childTid, 0)) != 0) {
if (err != ESRCH) if (err != ESRCH)
@ -280,12 +283,12 @@ void cThread::Cancel(int WaitSeconds)
} }
esyslog("ERROR: thread %ld won't end (waited %d seconds) - cancelling it...", childTid, WaitSeconds); esyslog("ERROR: thread %ld won't end (waited %d seconds) - cancelling it...", childTid, WaitSeconds);
} }
Lock(); childTidMutex.Lock();
if (childTid) { if (childTid) {
pthread_cancel(childTid); pthread_cancel(childTid);
childTid = 0; childTid = 0;
} }
Unlock(); childTidMutex.Unlock();
} }
} }

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: thread.h 1.24 2004/10/24 11:00:32 kls Exp $ * $Id: thread.h 1.25 2004/11/26 13:33:26 kls Exp $
*/ */
#ifndef __THREAD_H #ifndef __THREAD_H
@ -74,6 +74,7 @@ class cThread {
friend class cThreadLock; friend class cThreadLock;
private: private:
pthread_t parentTid, childTid; pthread_t parentTid, childTid;
cMutex childTidMutex;
cMutex mutex; cMutex mutex;
char *description; char *description;
static bool emergencyExitRequested; static bool emergencyExitRequested;