00001 #ifndef _MYTH_THREAD_H_
00002 #define _MYTH_THREAD_H_
00003
00004 #include <QThread>
00005
00006 #include "mythbaseexp.h"
00007
00008 class MThreadInternal;
00009 class QStringList;
00010 class QRunnable;
00011 class MThread;
00012
00014 bool MBASE_PUBLIC is_current_thread(MThread *thread);
00016 bool MBASE_PUBLIC is_current_thread(QThread *thread);
00018 bool MBASE_PUBLIC is_current_thread(MThread &thread);
00019
00044 class MBASE_PUBLIC MThread
00045 {
00046 friend class MThreadInternal;
00047 public:
00049 explicit MThread(const QString &objectName);
00054 explicit MThread(const QString &objectName, QRunnable *runnable);
00055 virtual ~MThread();
00056
00058 void RunProlog(void);
00061 void RunEpilog(void);
00062
00065 QThread *qthread(void);
00066
00067 void setObjectName(const QString &name);
00068 QString objectName(void) const;
00069
00070 void setPriority(QThread::Priority priority);
00071 QThread::Priority priority(void) const;
00072
00073 bool isFinished(void) const;
00074 bool isRunning(void) const;
00075
00076 void setStackSize(uint stackSize);
00077 uint stackSize(void) const;
00078
00080 void exit(int retcode = 0);
00082 void start(QThread::Priority = QThread::InheritPriority);
00090 void terminate(void);
00091 void quit(void);
00092
00095 static void ThreadSetup(const QString&);
00098 static void ThreadCleanup(void);
00099
00100 public:
00103 bool wait(unsigned long time = ULONG_MAX);
00104
00108 static void Cleanup(void);
00109 static void GetAllThreadNames(QStringList &list);
00110 static void GetAllRunningThreadNames(QStringList &list);
00111
00112 static const int kDefaultStartTimeout;
00113 protected:
00119 virtual void run(void);
00121 int exec(void);
00122
00123 static void setTerminationEnabled(bool enabled = true);
00124 static void sleep(unsigned long time);
00125 static void msleep(unsigned long time);
00126 static void usleep(unsigned long time);
00127
00128 MThreadInternal *m_thread;
00129 QRunnable *m_runnable;
00130 bool m_prolog_executed;
00131 bool m_epilog_executed;
00132 };
00133
00134 #endif // _MYTH_THREAD_H_