79#include <QCoreApplication>
83#include <QMutexLocker>
86#include <QRecursiveMutex>
88#include <QWaitCondition>
116 QMutexLocker locker(&
m_lock);
144 GetMythDB()->GetDBManager()->PurgeIdleConnections(
false);
145 qApp->processEvents();
146 qApp->sendPostedEvents(
nullptr, QEvent::DeferredDelete);
173 QMutexLocker locker(&
m_lock);
187 QMutexLocker locker(&
m_lock);
207 m_name(std::move(name)) {}
309 QList<MThreadPool*>::iterator it;
320 QList<MThreadPool*>::iterator it;
329 (*it)->DeletePoolThreads();
342 (*it).push_back(
MPoolEntry(runnable,debugName));
347 list.push_back(
MPoolEntry(runnable,debugName));
353 QRunnable *runnable,
const QString& debugName,
354 std::chrono::milliseconds waitForAvailMS)
362 auto left = waitForAvailMS -
t.elapsed();
367 left = waitForAvailMS -
t.elapsed();
381 QRunnable *runnable,
const QString& debugName,
bool reserved)
401 if (thread->
SetRunnable(runnable, debugName, reserved))
422 thread->SetRunnable(runnable, debugName, reserved);
424 if (thread->isRunning())
464 if (!thread->
SetRunnable(e.first, e.second,
false))
546static void print_set(QString title, QSet<MPoolThread*> set)
548 LOG(VB_GENERAL, LOG_INFO, title);
549 for (
auto item : std::as_const(set))
551 LOG(VB_GENERAL, LOG_INFO, QString(
" : 0x%1")
552 .arg((quint64)item,0,16));
554 LOG(VB_GENERAL, LOG_INFO,
"");
std::chrono::milliseconds m_expiryTimeout
MPoolThread(const QString &objectName, MThreadPool &pool, std::chrono::milliseconds timeout)
bool SetRunnable(QRunnable *runnable, QString runnableName, bool reserved)
void run(void) override
Runs the Qt event loop unless we have a QRunnable, in which case we run the runnable run instead.
QSet< MPoolThread * > m_runningThreads
static QList< MThreadPool * > s_all_pools
static QRecursiveMutex s_pool_lock
MThreadPoolPrivate(QString name)
std::chrono::milliseconds m_expiryTimeout
QSet< MPoolThread * > m_availThreads
int GetRealMaxThread(void) const
QList< MPoolThread * > m_deleteThreads
static MThreadPool * s_pool
int maxThreadCount(void) const
std::chrono::milliseconds expiryTimeout(void) const
void setExpiryTimeout(std::chrono::milliseconds expiryTimeout)
void DeletePoolThreads(void)
MThreadPool(const QString &name)
void setMaxThreadCount(int maxThreadCount)
MThreadPoolPrivate * m_priv
void startReserved(QRunnable *runnable, const QString &debugName, std::chrono::milliseconds waitForAvailMS=0ms)
bool tryStart(QRunnable *runnable, const QString &debugName)
void NotifyAvailable(MPoolThread *thread)
int activeThreadCount(void) const
static void StopAllPools(void)
static MThreadPool * globalInstance(void)
void start(QRunnable *runnable, const QString &debugName, int priority=0)
static void ShutdownAllPools(void)
void NotifyDone(MPoolThread *thread)
bool TryStartInternal(QRunnable *runnable, const QString &debugName, bool reserved)
This is a wrapper around QThread that does several additional things.
void RunProlog(void)
Sets up a thread, call this if you reimplement run().
void RunEpilog(void)
Cleans up a thread's resources, call this if you reimplement run().
bool wait(std::chrono::milliseconds time=std::chrono::milliseconds::max())
Wait for the MThread to exit, with a maximum timeout.
QString objectName(void) const
A QElapsedTimer based timer to replace use of QTime as a timer.
void loggingDeregisterThread(void)
Deregister the current thread's name.
void loggingRegisterThread(const QString &name)
Register the current thread with the given name.
QList< MPoolEntry > MPoolQueue
QPair< QRunnable *, QString > MPoolEntry
QMap< int, MPoolQueue > MPoolQueues
#define LOG(_MASK_, _LEVEL_, _QSTRING_)