26 #include <QStringList> 27 #include <QTimerEvent> 45 return QThread::currentThread() == thread->
qthread();
52 return QThread::currentThread() == thread;
57 return QThread::currentThread() == thread.
qthread();
65 purgeTimer = startTimer(5 * 60000);
69 if (event->timerId() == purgeTimer)
70 GetMythDB()->GetDBManager()->PurgeIdleConnections(
false);
79 void run(
void)
override { m_parent.run(); }
85 return QThread::exec();
89 { QThread::setTerminationEnabled(enabled); }
92 static void MSleep(
unsigned long time) { QThread::msleep(time); }
93 static void USleep(
unsigned long time) { QThread::usleep(time); }
104 m_prolog_executed(
true), m_epilog_executed(
true)
113 m_prolog_executed(
false), m_epilog_executed(
false)
124 LOG(VB_GENERAL, LOG_CRIT,
"MThread prolog was never run!");
128 LOG(VB_GENERAL, LOG_CRIT,
"MThread epilog was never run!");
132 LOG(VB_GENERAL, LOG_CRIT,
133 "MThread destructor called while thread still running!");
149 QSet<MThread*> badGuys;
150 QSet<MThread*>::const_iterator it;
153 if ((*it)->isRunning())
164 cerr<<
"Error: Not all threads were shut down properly: "<<endl;
165 for (it = badGuys.begin(); it != badGuys.end(); ++it)
167 cerr<<
"Thread "<<qPrintable((*it)->objectName())
168 <<
" is still running"<<endl;
172 static const int kTimeout = 5000;
175 for (it = badGuys.begin();
176 it != badGuys.end() &&
t.elapsed() < kTimeout; ++it)
178 int left = kTimeout -
t.elapsed();
187 QSet<MThread*>::const_iterator it;
189 list.push_back((*it)->objectName());
195 QSet<MThread*>::const_iterator it;
198 if ((*it)->isRunning())
199 list.push_back((*it)->objectName());
205 if (QThread::currentThread() !=
m_thread)
207 LOG(VB_GENERAL, LOG_CRIT,
208 "RunProlog can only be executed in the run() method of a thread.");
218 if (QThread::currentThread() !=
m_thread)
220 LOG(VB_GENERAL, LOG_CRIT,
221 "RunEpilog can only be executed in the run() method of a thread.");
231 #if QT_VERSION < QT_VERSION_CHECK(5,8,0) 241 GetMythDB()->GetDBManager()->CloseDatabases();
void RunEpilog(void)
Cleans up a thread's resources, call this if you reimplement run().
static QMutex s_all_threads_lock
void start(QThread::Priority=QThread::InheritPriority)
Tell MThread to start running the thread in the near future.
This is a wrapper around QThread that does several additional things.
A QElapsedTimer based timer to replace use of QTime as a timer.
void terminate(void)
Kill a thread unsafely.
VERBOSE_PREAMBLE Most true
MThreadInternal * m_thread
QString objectName(void) const
static void SetTerminationEnabled(bool enabled=true)
virtual void run(void)
Runs the Qt event loop unless we have a QRunnable, in which case we run the runnable run instead.
static void USleep(unsigned long time)
bool wait(unsigned long time=ULONG_MAX)
Wait for the MThread to exit, with a maximum timeout.
static void sleep(unsigned long time)
void loggingRegisterThread(const QString &name)
Register the current thread with the given name.
void setObjectName(const QString &name)
static void msleep(unsigned long time)
void timerEvent(QTimerEvent *event) override
MThread(const QString &objectName)
Standard constructor.
unsigned sleep(unsigned int x)
void setStackSize(uint stackSize)
static int run(MythMediaDevice *dev=nullptr, bool startRandomShow=false)
QDateTime current(bool stripped)
Returns current Date and Time in UTC.
static void GetAllRunningThreadNames(QStringList &list)
void setPriority(QThread::Priority priority)
void exit(int retcode=0)
Use this to exit from the thread if you are using a Qt event loop.
bool isRunning(void) const
static QSet< MThread * > s_all_threads
MThreadInternal(MThread &parent)
static void ThreadCleanup(void)
This is to be called on exit in those few threads that haven't been ported to MThread.
void loggingDeregisterThread(void)
Deregister the current thread's name.
static void Sleep(unsigned long time)
static void GetAllThreadNames(QStringList &list)
#define LOG(_MASK_, _LEVEL_, _STRING_)
QThread::Priority priority(void) const
static void Cleanup(void)
This will print out all the running threads, call exit(1) on each and then wait up to 5 seconds total...
static void MSleep(unsigned long time)
void RunProlog(void)
Sets up a thread, call this if you reimplement run().
QThread * qthread(void)
Returns the thread, this will always return the same pointer no matter how often you restart the thre...
static void ThreadSetup(const QString &)
This is to be called on startup in those few threads that haven't been ported to MThread.
uint stackSize(void) const
bool isFinished(void) const
bool is_current_thread(MThread *thread)
Use this to determine if you are in the named thread.
static void usleep(unsigned long time)
int exec(void)
Enters the qt event loop. call exit or quit to exit thread.
static void setTerminationEnabled(bool enabled=true)
void quit(void)
calls exit(0)