MythTV  master
mthread.h
Go to the documentation of this file.
1 #ifndef MYTH_THREAD_H
2 #define MYTH_THREAD_H
3 
4 #include <climits>
5 
6 #include <QThread>
7 
8 #include "mythbaseexp.h"
9 
10 class MThreadInternal;
11 class QStringList;
12 class QRunnable;
13 class MThread;
14 
18 bool MBASE_PUBLIC is_current_thread(QThread *thread);
21 
49 {
50  friend class MThreadInternal;
51  public:
53  explicit MThread(const QString &objectName);
58  explicit MThread(const QString &objectName, QRunnable *runnable);
59  virtual ~MThread();
60 
61  MThread(const MThread &) = delete; // not copyable
62  MThread &operator=(const MThread &) = delete; // not copyable
63 
65  void RunProlog(void);
68  void RunEpilog(void);
69 
72  QThread *qthread(void);
73 
74  void setObjectName(const QString &name);
75  QString objectName(void) const;
76 
77  void setPriority(QThread::Priority priority);
78  QThread::Priority priority(void) const;
79 
80  bool isFinished(void) const;
81  bool isRunning(void) const;
82 
83  void setStackSize(uint stackSize);
84  uint stackSize(void) const;
85 
87  void exit(int retcode = 0);
89  void start(QThread::Priority p = QThread::InheritPriority);
97  void terminate(void);
98  void quit(void);
99 
102  static void ThreadSetup(const QString& name);
105  static void ThreadCleanup(void);
106 
107  public:
110  bool wait(unsigned long time = ULONG_MAX);
111 
115  static void Cleanup(void);
116  static void GetAllThreadNames(QStringList &list);
117  static void GetAllRunningThreadNames(QStringList &list);
118 
119  static const int kDefaultStartTimeout;
120 
121  protected:
127  virtual void run(void);
129  int exec(void);
130 
131  static void setTerminationEnabled(bool enabled = true);
132  static void sleep(unsigned long time);
133  static void msleep(unsigned long time);
134  static void usleep(unsigned long time);
135 
136  MThreadInternal *m_thread {nullptr};
137  QRunnable *m_runnable {nullptr};
138  bool m_prologExecuted {true};
139  bool m_epilogExecuted {true};
140 };
141 
142 #endif // MYTH_THREAD_H
MThreadInternal::exec
int exec(void)
Definition: mthread.cpp:81
MThreadInternal::run
void run(void) override
Definition: mthread.cpp:78
mythbaseexp.h
sleep
unsigned sleep(unsigned int x)
Definition: compat.h:161
quit
@ quit
Definition: lirc_client.h:30
MBASE_PUBLIC
#define MBASE_PUBLIC
Definition: mythbaseexp.h:15
is_current_thread
bool MBASE_PUBLIC is_current_thread(MThread *thread)
Use this to determine if you are in the named thread.
Definition: mthread.cpp:40
MThreadInternal
Definition: mthread.cpp:75
hardwareprofile.config.p
p
Definition: config.py:33
uint
unsigned int uint
Definition: compat.h:141
MThread::kDefaultStartTimeout
static const int kDefaultStartTimeout
Definition: mthread.h:119
isRunning
static bool isRunning(const char *program)
Returns true if a program containing the specified string is running on this machine.
Definition: mythtv/programs/mythshutdown/main.cpp:202
MThread::operator=
MThread & operator=(const MThread &)=delete
MThread::MThread
MThread(const MThread &)=delete
MThread
This is a wrapper around QThread that does several additional things.
Definition: mthread.h:49