Go to the documentation of this file.
79 #include <QCoreApplication>
83 #include <QMutexLocker>
87 #include <QWaitCondition>
108 QMutexLocker locker(&
s_lock);
119 QMutexLocker locker(&
m_lock);
150 GetMythDB()->GetDBManager()->PurgeIdleConnections(
false);
151 qApp->processEvents();
152 qApp->sendPostedEvents(
nullptr, QEvent::DeferredDelete);
177 QMutexLocker locker(&
m_lock);
191 QMutexLocker locker(&
m_lock);
317 QList<MThreadPool*>::iterator it;
328 QList<MThreadPool*>::iterator it;
337 (*it)->DeletePoolThreads();
350 (*it).push_back(
MPoolEntry(runnable,debugName));
355 list.push_back(
MPoolEntry(runnable,debugName));
361 QRunnable *runnable,
const QString& debugName,
362 std::chrono::milliseconds waitForAvailMS)
370 auto left = waitForAvailMS -
t.elapsed();
375 left = waitForAvailMS -
t.elapsed();
389 QRunnable *runnable,
const QString& debugName,
bool reserved)
408 if (thread->
SetRunnable(runnable, debugName, reserved))
427 thread->SetRunnable(runnable, debugName, reserved);
429 if (thread->isRunning())
551 static void print_set(QString
title, QSet<MPoolThread*> set)
554 for (
auto item : qAsConst(set))
556 LOG(VB_GENERAL, LOG_INFO, QString(
" : 0x%1")
557 .
arg((quint64)item,0,16));
559 LOG(VB_GENERAL, LOG_INFO,
"");
void loggingDeregisterThread(void)
Deregister the current thread's name.
bool tryStart(QRunnable *runnable, const QString &debugName)
A QElapsedTimer based timer to replace use of QTime as a timer.
void run(void) override
Runs the Qt event loop unless we have a QRunnable, in which case we run the runnable run instead.
bool wait(std::chrono::milliseconds time=std::chrono::milliseconds::max())
Wait for the MThread to exit, with a maximum timeout.
std::chrono::milliseconds m_expiryTimeout
int maxThreadCount(void) const
void setObjectName(const QString &name)
arg(title).arg(filename).arg(doDelete))
MThreadPoolPrivate(QString name)
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
void RunProlog(void)
Sets up a thread, call this if you reimplement run().
bool SetRunnable(QRunnable *runnable, QString runnableName, bool reserved)
void startReserved(QRunnable *runnable, const QString &debugName, std::chrono::milliseconds waitForAvailMS=0ms)
void DeletePoolThreads(void)
int activeThreadCount(void) const
bool TryStartInternal(QRunnable *runnable, const QString &debugName, bool reserved)
static void ShutdownAllPools(void)
static void StopAllPools(void)
void loggingRegisterThread(const QString &name)
Register the current thread with the given name.
int GetRealMaxThread(void) const
void RunEpilog(void)
Cleans up a thread's resources, call this if you reimplement run().
QMap< int, MPoolQueue > MPoolQueues
static QList< MThreadPool * > s_all_pools
QList< MPoolEntry > MPoolQueue
void setExpiryTimeout(std::chrono::milliseconds expiryTimeout)
QList< MPoolThread * > m_deleteThreads
std::chrono::milliseconds m_expiryTimeout
QPair< QRunnable *, QString > MPoolEntry
void NotifyDone(MPoolThread *thread)
MThreadPoolPrivate * m_priv
MThreadPool(const QString &name)
static MThreadPool * s_pool
This is a wrapper around QThread that does several additional things.
std::chrono::milliseconds expiryTimeout(void) const
QString objectName(void) const
void setMaxThreadCount(int maxThreadCount)
void NotifyAvailable(MPoolThread *thread)
QSet< MPoolThread * > m_availThreads
MPoolThread(MThreadPool &pool, std::chrono::milliseconds timeout)
static MThreadPool * globalInstance(void)
QSet< MPoolThread * > m_runningThreads
void start(QRunnable *runnable, const QString &debugName, int priority=0)
static QMutex s_pool_lock