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 
60  void RunProlog(void);
63  void RunEpilog(void);
64 
67  QThread *qthread(void);
68 
69  void setObjectName(const QString &name);
70  QString objectName(void) const;
71 
72  void setPriority(QThread::Priority priority);
73  QThread::Priority priority(void) const;
74 
75  bool isFinished(void) const;
76  bool isRunning(void) const;
77 
78  void setStackSize(uint stackSize);
79  uint stackSize(void) const;
80 
82  void exit(int retcode = 0);
84  void start(QThread::Priority = QThread::InheritPriority);
92  void terminate(void);
93  void quit(void);
94 
97  static void ThreadSetup(const QString&);
100  static void ThreadCleanup(void);
101 
102  public:
105  bool wait(unsigned long time = ULONG_MAX);
106 
110  static void Cleanup(void);
111  static void GetAllThreadNames(QStringList &list);
112  static void GetAllRunningThreadNames(QStringList &list);
113 
114  static const int kDefaultStartTimeout;
115 
116  private:
117  MThread(const MThread &) = delete; // not copyable
118  MThread &operator=(const MThread &) = delete; // not copyable
119 
120  protected:
126  virtual void run(void);
128  int exec(void);
129 
130  static void setTerminationEnabled(bool enabled = true);
131  static void sleep(unsigned long time);
132  static void msleep(unsigned long time);
133  static void usleep(unsigned long time);
134 
135  MThreadInternal *m_thread {nullptr};
136  QRunnable *m_runnable {nullptr};
137  bool m_prolog_executed {true};
138  bool m_epilog_executed {true};
139 };
140 
141 #endif // _MYTH_THREAD_H_
This is a wrapper around QThread that does several additional things.
Definition: mthread.h:46
static const int kDefaultStartTimeout
Definition: mthread.h:114
unsigned int uint
Definition: compat.h:140
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 int run(MythMediaDevice *dev=nullptr, bool startRandomShow=false)
static bool isRunning(const char *program)
Returns true if a program containing the specified string is running on this machine.
const char * name
Definition: ParseText.cpp:328