79#include <QCoreApplication>
83#include <QMutexLocker>
86#include <QRecursiveMutex>
88#include <QWaitCondition>
115 QMutexLocker locker(&
m_lock);
143 GetMythDB()->GetDBManager()->PurgeIdleConnections(
false);
144 qApp->processEvents();
145 qApp->sendPostedEvents(
nullptr, QEvent::DeferredDelete);
171 QMutexLocker locker(&
m_lock);
185 QMutexLocker locker(&
m_lock);
307 QList<MThreadPool*>::iterator it;
318 QList<MThreadPool*>::iterator it;
327 (*it)->DeletePoolThreads();
340 (*it).push_back(
MPoolEntry(runnable,debugName));
345 list.push_back(
MPoolEntry(runnable,debugName));
351 QRunnable *runnable,
const QString& debugName,
352 std::chrono::milliseconds waitForAvailMS)
360 auto left = waitForAvailMS -
t.elapsed();
365 left = waitForAvailMS -
t.elapsed();
379 QRunnable *runnable,
const QString& debugName,
bool reserved)
399 if (thread->
SetRunnable(runnable, debugName, reserved))
420 thread->SetRunnable(runnable, debugName, reserved);
422 if (thread->isRunning())
462 if (!thread->
SetRunnable(e.first, e.second,
false))
544static void print_set(QString title, QSet<MPoolThread*> set)
546 LOG(VB_GENERAL, LOG_INFO, title);
547 for (
auto item : std::as_const(set))
549 LOG(VB_GENERAL, LOG_INFO, QString(
" : 0x%1")
550 .arg((quint64)item,0,16));
552 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_)