MythTV  master
mthread.h
Go to the documentation of this file.
1 #ifndef _MYTH_THREAD_H_
2 #define _MYTH_THREAD_H_
3 
4 #include <QThread>
5 
6 #include "mythbaseexp.h"
7 
8 class MThreadInternal;
9 class QStringList;
10 class QRunnable;
11 class MThread;
12 
16 bool MBASE_PUBLIC is_current_thread(QThread *thread);
19 
47 {
48  friend class MThreadInternal;
49  public:
51  explicit MThread(const QString &objectName);
56  explicit MThread(const QString &objectName, QRunnable *runnable);
57  virtual ~MThread();
58 
59  MThread(const MThread &) = delete; // not copyable
60  MThread &operator=(const MThread &) = delete; // not copyable
61 
63  void RunProlog(void);
66  void RunEpilog(void);
67 
70  QThread *qthread(void);
71 
72  void setObjectName(const QString &name);
73  QString objectName(void) const;
74 
75  void setPriority(QThread::Priority priority);
76  QThread::Priority priority(void) const;
77 
78  bool isFinished(void) const;
79  bool isRunning(void) const;
80 
81  void setStackSize(uint stackSize);
82  uint stackSize(void) const;
83 
85  void exit(int retcode = 0);
87  void start(QThread::Priority p = QThread::InheritPriority);
95  void terminate(void);
96  void quit(void);
97 
100  static void ThreadSetup(const QString& name);
103  static void ThreadCleanup(void);
104 
105  public:
108  bool wait(unsigned long time = ULONG_MAX);
109 
113  static void Cleanup(void);
114  static void GetAllThreadNames(QStringList &list);
115  static void GetAllRunningThreadNames(QStringList &list);
116 
117  static const int kDefaultStartTimeout;
118 
119  protected:
125  virtual void run(void);
127  int exec(void);
128 
129  static void setTerminationEnabled(bool enabled = true);
130  static void sleep(unsigned long time);
131  static void msleep(unsigned long time);
132  static void usleep(unsigned long time);
133 
134  MThreadInternal *m_thread {nullptr};
135  QRunnable *m_runnable {nullptr};
136  bool m_prologExecuted {true};
137  bool m_epilogExecuted {true};
138 };
139 
140 #endif // _MYTH_THREAD_H_
void run(void) override
Definition: mthread.cpp:79
This is a wrapper around QThread that does several additional things.
Definition: mthread.h:46
static const int kDefaultStartTimeout
Definition: mthread.h:117
bool MBASE_PUBLIC is_current_thread(MThread *thread)
Use this to determine if you are in the named thread.
Definition: mthread.cpp:41
int exec(void)
Definition: mthread.cpp:82
unsigned sleep(unsigned int x)
Definition: compat.h:159
#define MBASE_PUBLIC
Definition: mythbaseexp.h:15
static bool isRunning(const char *program)
Returns true if a program containing the specified string is running on this machine.
unsigned int uint
Definition: compat.h:140