Go to the documentation of this file.
79 #include <QCoreApplication>
83 #include <QMutexLocker>
86 #include <QRecursiveMutex>
88 #include <QWaitCondition>
109 QMutexLocker locker(&
s_lock);
120 QMutexLocker locker(&
m_lock);
151 GetMythDB()->GetDBManager()->PurgeIdleConnections(
false);
152 qApp->processEvents();
153 qApp->sendPostedEvents(
nullptr, QEvent::DeferredDelete);
178 QMutexLocker locker(&
m_lock);
192 QMutexLocker locker(&
m_lock);
217 m_name(std::move(name)) {}
318 QList<MThreadPool*>::iterator it;
329 QList<MThreadPool*>::iterator it;
338 (*it)->DeletePoolThreads();
351 (*it).push_back(
MPoolEntry(runnable,debugName));
356 list.push_back(
MPoolEntry(runnable,debugName));
362 QRunnable *runnable,
const QString& debugName,
363 std::chrono::milliseconds waitForAvailMS)
371 auto left = waitForAvailMS -
t.elapsed();
376 left = waitForAvailMS -
t.elapsed();
390 QRunnable *runnable,
const QString& debugName,
bool reserved)
410 if (thread->
SetRunnable(runnable, debugName, reserved))
429 thread->SetRunnable(runnable, debugName, reserved);
431 if (thread->isRunning())
471 if (!thread->
SetRunnable(e.first, e.second,
false))
553 static void print_set(QString title, QSet<MPoolThread*> set)
555 LOG(VB_GENERAL, LOG_INFO, title);
556 for (
auto item : std::as_const(set))
558 LOG(VB_GENERAL, LOG_INFO, QString(
" : 0x%1")
559 .arg((quint64)item,0,16));
561 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)
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)
static QRecursiveMutex s_pool_lock
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)