diff options
author | Klaus Schmidinger <vdr@tvdr.de> | 2000-10-08 09:25:20 +0200 |
---|---|---|
committer | Klaus Schmidinger <vdr@tvdr.de> | 2000-10-08 09:25:20 +0200 |
commit | 97c3bb61482855769f0208062610543475f02006 (patch) | |
tree | 98ed285302e4b4a9fcc6186587b2da234776ec14 /thread.h | |
parent | 60958ab1323d4f4750338165b89a99f4f2fbe4a7 (diff) | |
download | vdr-97c3bb61482855769f0208062610543475f02006.tar.gz vdr-97c3bb61482855769f0208062610543475f02006.tar.bz2 |
Remote control uses threads
Diffstat (limited to 'thread.h')
-rw-r--r-- | thread.h | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/thread.h b/thread.h new file mode 100644 index 00000000..86b9e922 --- /dev/null +++ b/thread.h @@ -0,0 +1,57 @@ +/* + * 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.1 2000/10/08 08:36:21 kls Exp $ + */ + +#ifndef __THREAD_H +#define __THREAD_H + +#include <pthread.h> +#include <sys/types.h> + +class cThread { + friend class cThreadLock; +private: + pthread_t thread; + pthread_mutex_t mutex; + pid_t parentPid, lockingPid; + int locked; + bool running; + static bool signalHandlerInstalled; + static void SignalHandler(int signum); + static void *StartThread(cThread *Thread); + bool Lock(void); + void Unlock(void); +protected: + void WakeUp(void); + virtual void Action(void) = 0; + void Stop(void); +public: + cThread(void); + virtual ~cThread(); + bool Start(void); + }; + +// 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); + ~cThreadLock(); + bool Locked(void); + }; + +#define LOCK_THREAD cThreadLock ThreadLock(this) + +#endif //__THREAD_H |