diff options
author | Klaus Schmidinger <kls (at) cadsoft (dot) de> | 2004-01-04 18:00:00 +0100 |
---|---|---|
committer | Klaus Schmidinger <kls (at) cadsoft (dot) de> | 2004-01-04 18:00:00 +0100 |
commit | 93a94b18b540fbcb9bcdaaea9abd26cdf23d6ee6 (patch) | |
tree | bede17e6cd329d36ec02bc53dfe567b95ec835a5 /thread.c | |
parent | c432905dd60630f906ac89f58592ad835a9063ef (diff) | |
download | vdr-patch-lnbsharing-93a94b18b540fbcb9bcdaaea9abd26cdf23d6ee6.tar.gz vdr-patch-lnbsharing-93a94b18b540fbcb9bcdaaea9abd26cdf23d6ee6.tar.bz2 |
Version 1.3.0vdr-1.3.0
- Changed thread handling to make it work with NPTL ("Native Posix Thread Library").
Thanks to Jon Burgess, Andreas Schultz, Werner Fink and Stefan Huelswitt.
- The cThread class now accepts a 'Description' parameter, which is used to log
the beginning and end of the thread, together with its process and thread id.
For descriptions that need additional parameters you can use the function
cThread::SetDescription(), which accepts 'printf()' like arguments.
Existing plugins that use threads should be changed to use this functionality
instead of explicit 'dsyslog()' calls inside their Action() function in order
to support logging the thread ids.
- Added "Slovak Link" and "Czech Link" to 'ca.conf' (thanks to Emil Petersky).
However, 'ca.conf' is now pretty much obsolete due to the automatic CA handling.
- Mutexes are now created with PTHREAD_MUTEX_ERRORCHECK_NP, which makes the
'lockingTid' stuff obsolete (thanks to Stefan Huelswitt).
- Changed font handling to allow language specific character sets.
- Adopted the small font character set from the "Elchi" patch (originally
provided by Alessio Sangalli).
- Greek language texts now use iso8859-7 character set (thanks to Dimitrios
Dimitrakos).
- Rearranged section data handling, so that the actual data handling can be done
separately, even from within plugins.
- The EPG data structures have been moved from eit.[hc] to epg.[hc] and have been
adapted to the general VDR coding style. Plugins that use these data structures
may need to change some function names (which should be obvious).
The name 'subtitle' has been changed to 'shortText' to avoid clashes with actual
subtitles that are part of a movie. The name 'extendedDescription' has been
shortened to 'description'.
- Replaced 'libdtv' with 'libsi' (thanks to Marcel Wiesweg), which is thread
safe and can be used by multiple section filters simultaneously.
- Added 'cRwLock' to 'thread.[hc]'. Note that all plugin Makefiles need to
define _GNU_SOURCE for this to work (see the example plugin Makefiles and
'newplugin').
- Fixed a problem with crc32 in SI handling on 64bit systems (thanks to Pedro
Miguel Sequeira de Justo Teixeira for reporting this one).
- Fixed an alignment problem in CAM access on 64bit systems (thanks to Pedro
Miguel Sequeira de Justo Teixeira for reporting this one).
- Added 'StreamType' setting to CAM communication, which is important for
Aston/SECA CAMs (thanks to Antonino Sergi).
- Now the CA descriptors are sent to the CAM in the 'program' or 'ES level'
sections, depending on where they are found in the PMT (thanks to Hans-Peter
Raschke for reporting this one). This should make SkyCrypt CAMs work.
- Now using the 'version number' of EPG events to avoid unnecessary work.
- Channel data is now automatically derived from the DVB data stream (inspired
by the 'autopid' patch from Andreas Schultz).
- The current channel is now automatically re-tuned if the PIDs or other settings
change. If a recording is going on on a channel that has a change in its
settings, the recording will be stopped and immediately restarted to use the
new channel settings.
- EPG events now use the complete channel ID with NID, TID and SID.
- Channel names in 'channels.conf' can now have a short form, as provided
by some tv stations (see man vdr(5)). Currently channels that provide short
names in addition to long ones are listed in the OSD as "short,long name",
as in "RTL,RTL Television". The short names will be used explicitly later.
- The Ca parameter in 'channels.conf' has been extended and now contains all the
CA system ids for the given channel. When switching to a channel VDR now tests
for a device that provides one of these CA system ids. The devices automatically
get their supported ids from the CI handler.
- The values in 'ca.conf' are currently without any real meaning. Whether or not
a channel with conditional access can be received is now determined automatically
by evaluating its CA descriptors and comparing them to the CA system ids
provided by the installed CAM. Only the special values 1-16 are used to assign
a channel to a particular device.
- Increased the maximum number of possible OSD colors to 256.
- Limited the line length in the EPG bugfix report, which appears to fix a buffer
overflow that caused a crash when cleaning up the EPG data (at 05:00 in the
morning).
Diffstat (limited to 'thread.c')
-rw-r--r-- | thread.c | 112 |
1 files changed, 85 insertions, 27 deletions
@@ -4,12 +4,14 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: thread.c 1.25 2003/05/18 12:45:13 kls Exp $ + * $Id: thread.c 1.30 2004/01/03 16:59:33 kls Exp $ */ #include "thread.h" #include <errno.h> +#include <malloc.h> #include <signal.h> +#include <stdarg.h> #include <sys/resource.h> #include <sys/time.h> #include <sys/wait.h> @@ -30,7 +32,7 @@ cCondVar::~cCondVar() void cCondVar::Wait(cMutex &Mutex) { - if (Mutex.locked && Mutex.lockingPid == getpid()) { + if (Mutex.locked) { int locked = Mutex.locked; Mutex.locked = 0; // have to clear the locked count here, as pthread_cond_wait // does an implizit unlock of the mutex @@ -43,7 +45,7 @@ bool cCondVar::TimedWait(cMutex &Mutex, int TimeoutMs) { bool r = true; // true = condition signaled false = timeout - if (Mutex.locked && Mutex.lockingPid == getpid()) { + if (Mutex.locked) { struct timeval now; // unfortunately timedwait needs the absolute time, not the delta :-( if (gettimeofday(&now, NULL) == 0) { // get current time now.tv_usec += TimeoutMs * 1000; // add the timeout @@ -61,7 +63,6 @@ bool cCondVar::TimedWait(cMutex &Mutex, int TimeoutMs) if (pthread_cond_timedwait(&cond, &Mutex.mutex, &abstime) == ETIMEDOUT) r = false; Mutex.locked = locked; - Mutex.lockingPid = getpid(); } } return r; @@ -79,13 +80,46 @@ void cCondVar::Signal(void) } */ +// --- cRwLock --------------------------------------------------------------- + +cRwLock::cRwLock(bool PreferWriter) +{ + pthread_rwlockattr_t attr = { PreferWriter ? PTHREAD_RWLOCK_PREFER_WRITER_NP : PTHREAD_RWLOCK_PREFER_READER_NP }; + pthread_rwlock_init(&rwlock, &attr); +} + +cRwLock::~cRwLock() +{ + pthread_rwlock_destroy(&rwlock); +} + +bool cRwLock::Lock(bool Write, int TimeoutMs) +{ + int Result = 0; + struct timespec abstime; + if (TimeoutMs) { + abstime.tv_sec = TimeoutMs / 1000; + abstime.tv_nsec = (TimeoutMs % 1000) * 1000000; + } + if (Write) + Result = TimeoutMs ? pthread_rwlock_timedwrlock(&rwlock, &abstime) : pthread_rwlock_wrlock(&rwlock); + else + Result = TimeoutMs ? pthread_rwlock_timedrdlock(&rwlock, &abstime) : pthread_rwlock_rdlock(&rwlock); + return Result == 0; +} + +void cRwLock::Unlock(void) +{ + pthread_rwlock_unlock(&rwlock); +} + // --- cMutex ---------------------------------------------------------------- cMutex::cMutex(void) { - lockingPid = 0; locked = 0; - pthread_mutex_init(&mutex, NULL); + pthread_mutexattr_t attr = { PTHREAD_MUTEX_ERRORCHECK_NP }; + pthread_mutex_init(&mutex, &attr); } cMutex::~cMutex() @@ -95,19 +129,14 @@ cMutex::~cMutex() void cMutex::Lock(void) { - if (getpid() != lockingPid || !locked) { - pthread_mutex_lock(&mutex); - lockingPid = getpid(); - } + pthread_mutex_lock(&mutex); locked++; } void cMutex::Unlock(void) { - if (!--locked) { - lockingPid = 0; + if (!--locked) pthread_mutex_unlock(&mutex); - } } // --- cThread --------------------------------------------------------------- @@ -118,18 +147,33 @@ void cMutex::Unlock(void) bool cThread::signalHandlerInstalled = false; bool cThread::emergencyExitRequested = false; -cThread::cThread(void) +cThread::cThread(const char *Description) { if (!signalHandlerInstalled) { signal(SIGIO, SignalHandler); signalHandlerInstalled = true; } running = false; - parentPid = threadPid = 0; + parentTid = childTid = 0; + description = NULL; + SetDescription(Description); } cThread::~cThread() { + free(description); +} + +void cThread::SetDescription(const char *Description, ...) +{ + free(description); + description = NULL; + if (Description) { + va_list ap; + va_start(ap, Description); + vasprintf(&description, Description, ap); + va_end(ap); + } } void cThread::SignalHandler(int signum) @@ -139,8 +183,13 @@ void cThread::SignalHandler(int signum) void *cThread::StartThread(cThread *Thread) { - Thread->threadPid = getpid(); + Thread->childTid = pthread_self(); + 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->childTid = 0; return NULL; } @@ -148,9 +197,9 @@ bool cThread::Start(void) { if (!running) { running = true; - parentPid = getpid(); - pthread_create(&thread, NULL, (void *(*) (void *))&StartThread, (void *)this); - pthread_setschedparam(thread, SCHED_RR, 0); + parentTid = pthread_self(); + pthread_create(&childTid, NULL, (void *(*) (void *))&StartThread, (void *)this); + 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()??? @@ -158,12 +207,21 @@ bool cThread::Start(void) bool cThread::Active(void) { - if (threadPid) { - if (kill(threadPid, SIGIO) < 0) { // couldn't find another way of checking whether the thread is still running - any ideas? - if (errno == ESRCH) - threadPid = 0; - else + if (childTid) { + // + // Single UNIX Spec v2 says: + // + // The pthread_kill() function is used to request + // that a signal be delivered to the specified thread. + // + // As in kill(), if sig is zero, error checking is + // performed but no signal is actually sent. + // + int err; + if ((err = pthread_kill(childTid, 0)) != 0) { + if (err != ESRCH) LOG_ERROR; + childTid = 0; } else return true; @@ -180,14 +238,14 @@ void cThread::Cancel(int WaitSeconds) return; usleep(10000); } - esyslog("ERROR: thread %d won't end (waited %d seconds) - cancelling it...", threadPid, WaitSeconds); + esyslog("ERROR: thread %ld won't end (waited %d seconds) - cancelling it...", childTid, WaitSeconds); } - pthread_cancel(thread); + pthread_cancel(childTid); } void cThread::WakeUp(void) { - kill(parentPid, SIGIO); // makes any waiting 'select()' call return immediately + pthread_kill(parentTid, SIGIO); // makes any waiting 'select()' call return immediately } bool cThread::EmergencyExit(bool Request) |