From ccb0add798961ce2fa24f625a00106cb0d3df709 Mon Sep 17 00:00:00 2001 From: Klaus Schmidinger Date: Sat, 13 Aug 2005 13:17:24 +0200 Subject: Centralized 'thread active' handling --- thread.h | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'thread.h') diff --git a/thread.h b/thread.h index 48d04990..35b2fee1 100644 --- a/thread.h +++ b/thread.h @@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: thread.h 1.28 2005/05/29 11:31:24 kls Exp $ + * $Id: thread.h 1.29 2005/08/13 13:01:33 kls Exp $ */ #ifndef __THREAD_H @@ -76,6 +76,7 @@ class cThread { friend class cThreadLock; private: bool running; + bool active; pthread_t childTid; cMutex mutex; char *description; @@ -86,13 +87,30 @@ protected: 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 Active() repeatedly to see whether + ///< it's time to stop. + bool Active(void) { return active; } + ///< Returns false if a derived cThread object shall leave its Action() + ///< function. void Cancel(int WaitSeconds = 0); + ///< Cancels the thread by first setting 'active' 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. 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, ...); bool Start(void); - bool Active(void); + ///< Actually starts the thread. + bool Running(void); + ///< Checks whether the thread is actually running. static bool EmergencyExit(bool Request = false); }; -- cgit v1.2.3