mirror of
https://github.com/vdr-projects/vdr.git
synced 2025-03-01 10:50:46 +00:00
- Added cDevice::HasCi() so that devices with Common Interface can be avoided when tuning to an FTA channel, thus preserving the CAM resources even on budget DVB cards (suggested by Petri Helin). - Fixed i18n characters for the Hungarian texts (thanks to Thomas Günther). - Now using cPipe instead of popen() in cCommand::Execute() to avoid problems with open file handles when starting background commands (thanks to Reinhard Nissl). - Removed 'assert(0)' from cDvbSpuDecoder::setTime() (thanks to Marco Schlüßler). - Fixed a possible crash when loading an invalid XPM file (thanks to Martin Wache). - Updated satellite names in 'sources.conf' (thanks to Thilo Wunderlich). - Adapted 'libsi' to DVB-S2 (thanks to Marco Schlüßler). - Fixed handling error status in cDvbTuner::GetFrontendStatus() (thanks to Reinhard Nissl). - Shutdown handling has been rewritten (thanks to Udo Richter). - Plugins can now implement the new function WakeupTime() to request VDR to wake up at a particular time (thanks to Udo Richter). - The HUP signal now forces a restart of VDR (thanks to Udo Richter). - cThread::EmergencyExit() has been replaced by ShutdownHandler.RequestEmergencyExit(). - Several references to "button" in a remote control context have been changed to "key" (based on a report from Marko Mäkelä regarding the "Menu button closes" text). The "MenuButtonCloses" parameter in 'setup.conf' has therefore been renamed to "MenuKeyCloses", accordingly. This will result in an "unknown config parameter: MenuButtonCloses" error message in the log file, so you may want to remove that entry from your 'setup.conf' file. - Simplified the error handling in cDvbTuner::GetFrontendStatus() (based on a discussion with Reinhard Nissl). - Updated the Finnish OSD texts (thanks to Rolf Ahrenberg). - Increased the maximum number of DVB devices to 8 (thanks to Rolf Ahrenberg). - The new Setup parameter "Channel entry timeout" can be used to customize the time since the last keypress until a numerically entered channel number is considered complete, and the channel is switched (suggested by Helmut Auer). Setting this parameter to 0 turns off the automatic channel switching, and the user will have to confirm the entry by pressing the "Ok" key.
182 lines
5.3 KiB
C++
182 lines
5.3 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.39 2007/02/24 16:13:28 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".
|
|
///< In order to avoid a possible busy wait, TimeoutMs will be automatically
|
|
///< limited to values >2.
|
|
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);
|
|
};
|
|
|
|
typedef pid_t tThreadId;
|
|
|
|
class cThread {
|
|
friend class cThreadLock;
|
|
private:
|
|
bool active;
|
|
bool running;
|
|
pthread_t childTid;
|
|
tThreadId childThreadId;
|
|
cMutex mutex;
|
|
char *description;
|
|
static tThreadId mainThreadId;
|
|
static void *StartThread(cThread *Thread);
|
|
protected:
|
|
void SetPriority(int Priority);
|
|
void Lock(void) { mutex.Lock(); }
|
|
void Unlock(void) { mutex.Unlock(); }
|
|
virtual void Action(void) = 0;
|
|
///< A derived cThread class must implement the code it wants to
|
|
///< execute as a separate thread in this function. If this is
|
|
///< a loop, it must check Running() repeatedly to see whether
|
|
///< it's time to stop.
|
|
bool Running(void) { return running; }
|
|
///< Returns false if a derived cThread object shall leave its Action()
|
|
///< function.
|
|
void Cancel(int WaitSeconds = 0);
|
|
///< Cancels the thread by first setting 'running' to false, so that
|
|
///< the Action() loop can finish in an orderly fashion and then waiting
|
|
///< up to WaitSeconds seconds for the thread to actually end. If the
|
|
///< thread doesn't end by itself, it is killed.
|
|
///< If WaitSeconds is -1, only 'running' is set to false and Cancel()
|
|
///< returns immediately, without killing the thread.
|
|
public:
|
|
cThread(const char *Description = NULL);
|
|
///< Creates a new thread.
|
|
///< If Description is present, a log file entry will be made when
|
|
///< the thread starts and stops. The Start() function must be called
|
|
///< to actually start the thread.
|
|
virtual ~cThread();
|
|
void SetDescription(const char *Description, ...) __attribute__ ((format (printf, 2, 3)));
|
|
bool Start(void);
|
|
///< Actually starts the thread.
|
|
///< If the thread is already running, nothing happens.
|
|
bool Active(void);
|
|
///< Checks whether the thread is still alive.
|
|
static tThreadId ThreadId(void);
|
|
static tThreadId IsMainThread(void) { return ThreadId() == mainThreadId; }
|
|
static void SetMainThreadId(void);
|
|
};
|
|
|
|
// 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.
|
|
// With Detached=true, calls command in background and in a separate session,
|
|
// with stdin connected to /dev/null.
|
|
|
|
int SystemExec(const char *Command, bool Detached = false);
|
|
|
|
#endif //__THREAD_H
|