63#ifndef QT_NO_EXCEPTIONS
67#ifndef QT_NO_EXCEPTIONS
69 qWarning(
"Qt Concurrent has caught an exception thrown from a worker thread.\n"
70 "This is not supported, exceptions thrown in worker threads must be\n"
71 "caught before control returns to Qt Concurrent.");
93 if (
page->isFinished()) {
185 return p->priority() < priority;
192 if (
page->priority() == priority && !
page->isFull()) {
193 page->push(runnable);
219 if (
page->isFinished()) {
244 auto thread = std::make_unique<QThreadPoolThread>(
this);
252 thread->runnable = runnable;
266 auto allThreadsCopy = std::exchange(
allThreads, {});
273 if (thread->isRunning()) {
274 thread->runnableReady.wakeAll();
314 while (!
page->isFinished()) {
316 if (
r &&
r->autoDelete()) {
347 if (runnable ==
nullptr)
352 if (
page->tryTake(runnable)) {
353 if (
page->isFinished()) {
354 d->queue.removeOne(
page);
373 if (!
q->tryTake(runnable))
447 d->objectName = newName;
515 if (!
d->tryStart(runnable))
516 d->enqueueTask(runnable, priority);
559 if (
d->tryStart(runnable))
601 return d->expiryTimeout;
629 return d->requestedMaxThreadCount;
641 d->tryToStartMoreThreads();
658 return d->activeThreadCount();
680 ++
d->reservedThreads;
727 d->threadPriority = priority;
734 return d->threadPriority;
753 --
d->reservedThreads;
754 d->tryToStartMoreThreads();
784 --
d->reservedThreads;
786 if (!
d->tryStart(runnable)) {
789 d->enqueueTask(runnable, INT_MAX);
817 return d->waitForDone(msecs);
852#include "moc_qthreadpool.cpp"
853#include "qthreadpool.moc"
QByteArray first(qsizetype n) const
static bool closingDown()
Returns true if the application objects are being destroyed; otherwise returns false.
qsizetype size() const noexcept
void removeFirst() noexcept
bool isEmpty() const noexcept
iterator insert(qsizetype i, parameter_type t)
bool removeOne(const AT &t)
const_iterator constBegin() const noexcept
const_iterator constEnd() const noexcept
void unlock() noexcept
Unlocks this mutex locker.
void relock() noexcept
Relocks an unlocked mutex locker.
Mutex * mutex() const noexcept
Returns the mutex on which the QMutexLocker is operating.
void unlock() noexcept
Unlocks the mutex.
void lock() noexcept
Locks the mutex.
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
QThread * thread() const
Returns the thread in which the object lives.
void objectNameChanged(const QString &objectName, QPrivateSignal)
This signal is emitted after the object's name has been changed.
void enqueue(const T &t)
Adds value t to the tail of the queue.
T dequeue()
Removes the head item in the queue and returns it.
bool autoDelete() const
Returns true is auto-deletion is enabled; false otherwise.
virtual void run()=0
Implement this pure virtual function in your subclass.
bool contains(const T &value) const
iterator insert(const T &value)
\macro QT_RESTRICTED_CAST_FROM_ASCII
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
bool areAllThreadsActive() const
bool waitForDone(int msecs)
bool tryStart(QRunnable *task)
void enqueueTask(QRunnable *task, int priority=0)
void tryToStartMoreThreads()
QList< QueuePage * > queue
QThread::Priority threadPriority
QWaitCondition noActiveThreads
QQueue< QThreadPoolThread * > expiredThreads
int activeThreadCount() const
int maxThreadCount() const
QSet< QThreadPoolThread * > allThreads
void startThread(QRunnable *runnable=nullptr)
void stealAndRunRunnable(QRunnable *runnable)
QQueue< QThreadPoolThread * > waitingThreads
static QThreadPool * qtGuiInstance()
Returns the QThreadPool instance for Qt Gui.
bool tooManyThreadsActive() const
QThreadPoolThread(QThreadPoolPrivate *manager)
QThreadPoolPrivate * manager
void registerThreadInactive()
QWaitCondition runnableReady
void reserveThread()
Reserves one thread, disregarding activeThreadCount() and maxThreadCount().
void start(QRunnable *runnable, int priority=0)
Reserves a thread and uses it to run runnable, unless this thread will make the current thread count ...
static QThreadPool * globalInstance()
Returns the global QThreadPool instance.
void setExpiryTimeout(int expiryTimeout)
int activeThreadCount
the number of active threads in the thread pool.
void setMaxThreadCount(int maxThreadCount)
void startOnReservedThread(QRunnable *runnable)
Releases a thread previously reserved with reserveThread() and uses it to run runnable.
bool tryTake(QRunnable *runnable)
void setThreadPriority(QThread::Priority priority)
QThreadPool(QObject *parent=nullptr)
Constructs a thread pool with the given parent.
int maxThreadCount
the maximum number of threads used by the thread pool.
uint stackSize
the stack size for the thread pool worker threads.
void setStackSize(uint stackSize)
~QThreadPool()
Destroys the QThreadPool.
bool contains(const QThread *thread) const
bool tryStart(QRunnable *runnable)
Attempts to reserve a thread to run runnable.
void releaseThread()
Releases a thread previously reserved by a call to reserveThread().
int expiryTimeout
the thread expiry timeout value in milliseconds.
QThread::Priority threadPriority
the thread priority for new worker threads.
bool waitForDone(int msecs=-1)
Waits up to msecs milliseconds for all threads to exit and removes all threads from the thread pool.
void start(Priority=InheritPriority)
bool wait(QDeadlineTimer deadline=QDeadlineTimer(QDeadlineTimer::Forever))
void setStackSize(uint stackSize)
bool wait(QMutex *, QDeadlineTimer=QDeadlineTimer(QDeadlineTimer::Forever))
QSet< QString >::iterator it
Combined button and popup list for selecting options.
GLdouble GLdouble GLdouble GLdouble q
bool comparePriority(int priority, const QueuePage *p)
QNetworkAccessManager manager
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent