mirror of
https://github.com/vdr-projects/vdr.git
synced 2025-03-01 10:50:46 +00:00
- Fixed detecting transponder lock in cDvbTuner (based on a patch from Stefan Meyknecht). - What was previously marked with WAIT_FOR_LOCK_AFTER_TUNING is now permanently active and uses a cCondVar to signal when a transponder is locked. - Added some missing 'const' to cChannel. - Added a sample setup for 'DisiCon-4 Single Cable Network' to 'diseqc.conf' (thanks to Oliver Endriss). - Fixed attaching a cPlayer to a cDevice, so that 'Operation not permitted' errors don't occur any more (thanks to Marco Schlüßler). - Fixed a case where the resultBuffer in cRemux ran full before getting a sync. - Removed the usleep() call from cDvbPlayer::Action() to make VDR run on NPTL systems (thanks to Alfred Zastrow). The NPTL check at startup has also been removed. - Taking the complete size of available data into account when deciding whether to clear the transfer buffer to avoid overflows (thanks to Reinhard Nissl). - Updated Romanian language texts and the iso8859-2 fonts (thanks to Lucian Muresan). - Now actually using the iso8859-15 fonts (thanks to Lucian Muresan). - Some minor code cleanups (thanks to Prakash K. Cheemplavam). - Fixed missing cleanup at program exit in case there is a problem with a plugin (thanks to Mattias Grönlund for pointing this out). - Increased the required free buffer space in the resultBuffer of cRemux to 2 * IPACKS to avoid a buffer overflow in case a cTS2PES writes one complete packet and then (within processing the same TS packet) wants to write another small packet. - Removed the signal handler and WakeUp() call from cThread (it is no longer needed). - Added some checks when canceling 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. - Added cCondWait::Sleep() and using it to replace all usleep() calls (based on a suggestion by Werner Fink). - Only assigning events to timers if the related schedule has actually been modified. - When searching for the present event, the running status is now only taken into account if the event has been "seen" within the past 30 seconds. This avoids shortly seeing the wrong events in the channel display when switching to a channel that hasn't been tuned to in a while.
150 lines
3.6 KiB
C++
150 lines
3.6 KiB
C++
/*
|
|
* thread.h: A simple thread base class
|
|
*
|
|
* 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 $
|
|
*/
|
|
|
|
#ifndef __THREAD_H
|
|
#define __THREAD_H
|
|
|
|
#include <pthread.h>
|
|
#include <stdio.h>
|
|
#include <sys/types.h>
|
|
|
|
class cCondWait {
|
|
private:
|
|
pthread_mutex_t mutex;
|
|
pthread_cond_t cond;
|
|
bool signaled;
|
|
public:
|
|
cCondWait(void);
|
|
~cCondWait();
|
|
static void SleepMs(int TimeoutMs);
|
|
///< Creates a cCondWait object and uses it to sleep for TimeoutMs
|
|
///< milliseconds, immediately giving up the calling thread's time
|
|
///< slice and thus avoiding a "busy wait".
|
|
bool Wait(int TimeoutMs = 0);
|
|
///< Waits at most TimeoutMs milliseconds for a call to Signal(), or
|
|
///< forever if TimeoutMs is 0.
|
|
///< \return Returns true if Signal() has been called, false it the given
|
|
///< timeout has expired.
|
|
void Signal(void);
|
|
///< Signals a caller of Wait() that the condition it is waiting for is met.
|
|
};
|
|
|
|
class cMutex;
|
|
|
|
class cCondVar {
|
|
private:
|
|
pthread_cond_t cond;
|
|
public:
|
|
cCondVar(void);
|
|
~cCondVar();
|
|
void Wait(cMutex &Mutex);
|
|
bool TimedWait(cMutex &Mutex, int TimeoutMs);
|
|
void Broadcast(void);
|
|
};
|
|
|
|
class cRwLock {
|
|
private:
|
|
pthread_rwlock_t rwlock;
|
|
public:
|
|
cRwLock(bool PreferWriter = false);
|
|
~cRwLock();
|
|
bool Lock(bool Write, int TimeoutMs = 0);
|
|
void Unlock(void);
|
|
};
|
|
|
|
class cMutex {
|
|
friend class cCondVar;
|
|
private:
|
|
pthread_mutex_t mutex;
|
|
int locked;
|
|
public:
|
|
cMutex(void);
|
|
~cMutex();
|
|
void Lock(void);
|
|
void Unlock(void);
|
|
};
|
|
|
|
class cThread {
|
|
friend class cThreadLock;
|
|
private:
|
|
pthread_t parentTid, childTid;
|
|
cMutex mutex;
|
|
char *description;
|
|
static bool emergencyExitRequested;
|
|
static void *StartThread(cThread *Thread);
|
|
protected:
|
|
void Lock(void) { mutex.Lock(); }
|
|
void Unlock(void) { mutex.Unlock(); }
|
|
virtual void Action(void) = 0;
|
|
void Cancel(int WaitSeconds = 0);
|
|
public:
|
|
cThread(const char *Description = NULL);
|
|
virtual ~cThread();
|
|
void SetDescription(const char *Description, ...);
|
|
bool Start(void);
|
|
bool Active(void);
|
|
static bool EmergencyExit(bool Request = false);
|
|
};
|
|
|
|
// cMutexLock can be used to easily set a lock on mutex and make absolutely
|
|
// sure that it will be unlocked when the block will be left. Several locks can
|
|
// be stacked, so a function that makes many calls to another function which uses
|
|
// cMutexLock may itself use a cMutexLock to make one longer lock instead of many
|
|
// short ones.
|
|
|
|
class cMutexLock {
|
|
private:
|
|
cMutex *mutex;
|
|
bool locked;
|
|
public:
|
|
cMutexLock(cMutex *Mutex = NULL);
|
|
~cMutexLock();
|
|
bool Lock(cMutex *Mutex);
|
|
};
|
|
|
|
// cThreadLock can be used to easily set a lock in a thread and make absolutely
|
|
// sure that it will be unlocked when the block will be left. Several locks can
|
|
// be stacked, so a function that makes many calls to another function which uses
|
|
// cThreadLock may itself use a cThreadLock to make one longer lock instead of many
|
|
// short ones.
|
|
|
|
class cThreadLock {
|
|
private:
|
|
cThread *thread;
|
|
bool locked;
|
|
public:
|
|
cThreadLock(cThread *Thread = NULL);
|
|
~cThreadLock();
|
|
bool Lock(cThread *Thread);
|
|
};
|
|
|
|
#define LOCK_THREAD cThreadLock ThreadLock(this)
|
|
|
|
// cPipe implements a pipe that closes all unnecessary file descriptors in
|
|
// the child process.
|
|
|
|
class cPipe {
|
|
private:
|
|
pid_t pid;
|
|
FILE *f;
|
|
public:
|
|
cPipe(void);
|
|
~cPipe();
|
|
operator FILE* () { return f; }
|
|
bool Open(const char *Command, const char *Mode);
|
|
int Close(void);
|
|
};
|
|
|
|
// SystemExec() implements a 'system()' call that closes all unnecessary file
|
|
// descriptors in the child process.
|
|
|
|
int SystemExec(const char *Command);
|
|
|
|
#endif //__THREAD_H
|