Home

Dokumentation

Impressum

Dokumentation VDR
 

Main Page   Class Hierarchy   Alphabetical List   Data Structures   File List   Data Fields   Globals  

thread.h

Go to the documentation of this file.
00001 
00010 #ifndef __THREAD_H
00011 #define __THREAD_H
00012 
00013 #include <pthread.h>
00014 #include <stdio.h>
00015 #include <sys/types.h>
00016 
00017 class cMutex;
00018 
00020 class cCondVar {
00021 private:
00022   pthread_cond_t cond;
00023 public:
00024   cCondVar(void);
00025   ~cCondVar();
00026   void Wait(cMutex &Mutex);
00027   bool TimedWait(cMutex &Mutex, int TimeoutMs);
00028   void Broadcast(void);
00029   //void Signal(void);
00030   };
00031 
00033 class cMutex {
00034   friend class cCondVar;
00035 private:
00036   pthread_mutex_t mutex;
00037   pid_t lockingPid;
00038   int locked;
00039 public:
00040   cMutex(void);
00041   ~cMutex();
00042   void Lock(void);
00043   void Unlock(void);
00044   };
00045 
00047 class cThread {
00048   friend class cThreadLock;
00049 private:
00050   pthread_t thread;
00051   cMutex mutex;
00052   pid_t parentPid, threadPid;
00053   bool running;
00054   static time_t lastPanic;
00055   static int panicLevel;
00056   static bool emergencyExitRequested;
00057   static bool signalHandlerInstalled;
00058   static void SignalHandler(int signum);
00059   static void *StartThread(cThread *Thread);
00060 protected:
00061   void Lock(void) { mutex.Lock(); }
00062   void Unlock(void) { mutex.Unlock(); }
00063   void WakeUp(void);
00064   virtual void Action(void) = 0;
00065   void Cancel(int WaitSeconds = 0);
00066 public:
00067   cThread(void);
00068   virtual ~cThread();
00069   bool Start(void);
00070   bool Active(void);
00071   static void RaisePanic(void);
00072   static bool EmergencyExit(bool Request = false);
00073   };
00074 
00076 class cMutexLock {
00077 
00086 private:
00087   cMutex *mutex;
00088   bool locked;
00089 public:
00090   cMutexLock(cMutex *Mutex = NULL);
00091   ~cMutexLock();
00092   bool Lock(cMutex *Mutex);
00093   };
00094 
00096 class cThreadLock {
00097 
00105 private:
00106   cThread *thread;
00107   bool locked;
00108 public:
00109   cThreadLock(cThread *Thread = NULL);
00110   ~cThreadLock();
00111   bool Lock(cThread *Thread);
00112   };
00113 
00114 #define LOCK_THREAD cThreadLock ThreadLock(this)
00115 
00117 class cPipe {
00118 
00123 private:
00124   pid_t pid;
00125   FILE *f;
00126 public:
00127   cPipe(void);
00128   ~cPipe();
00129   operator FILE* () { return f; }
00130   bool Open(const char *Command, const char *Mode);
00131   int Close(void);
00132   };
00133 
00138 int SystemExec(const char *Command);
00139 
00140 #endif //__THREAD_H
00141 

Generated on Wed Feb 5 23:30:12 2003 for VDR by doxygen1.3-rc2