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.
- 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
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
* 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"
@ -221,19 +221,22 @@ void cThread::SetDescription(const char *Description, ...)
void *cThread::StartThread(cThread *Thread)
{
Thread->childTidMutex.Lock();
Thread->childTid = pthread_self();
Thread->childTidMutex.Unlock();
if (Thread->description)
dsyslog("%s thread started (pid=%d, tid=%ld)", Thread->description, getpid(), Thread->childTid);
Thread->Action();
if (Thread->description)
dsyslog("%s thread ended (pid=%d, tid=%ld)", Thread->description, getpid(), Thread->childTid);
Thread->childTidMutex.Lock();
Thread->childTid = 0;
Thread->childTidMutex.Unlock();
return NULL;
}
bool cThread::Start(void)
{
Lock();
if (!childTid) {
parentTid = pthread_self();
pthread_t Tid;
@ -241,7 +244,6 @@ bool cThread::Start(void)
pthread_detach(Tid); // auto-reap
pthread_setschedparam(Tid, SCHED_RR, 0);
}
Unlock();
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
// performed but no signal is actually sent.
//
cMutexLock MutexLock(&childTidMutex);
int err;
if ((err = pthread_kill(childTid, 0)) != 0) {
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);
}
Lock();
childTidMutex.Lock();
if (childTid) {
pthread_cancel(childTid);
childTid = 0;
}
Unlock();
childTidMutex.Unlock();
}
}

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.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
@ -74,6 +74,7 @@ class cThread {
friend class cThreadLock;
private:
pthread_t parentTid, childTid;
cMutex childTidMutex;
cMutex mutex;
char *description;
static bool emergencyExitRequested;