QThreadPool: replace a QSet with a QList
QThreadPool maintains three containers of QThreadPoolThread*: - allThreads, a QSet - waitingThreads, a QQueue - expiredThreads, also a QQueue None of the operations on allThreads make use of QSets fast lookup. The only functions called on it are isEmpty(), count(), insert(), and swap(). Since therefore QSet adds nothing but overhead, causes indeterminism (e.g. when deleting threads in Private::reset()) and code bloat, use the same container for allThreads that underlies QQueue: QList. Port insert() to append(). Add an assert to verify that we're not running into an ABA problem here (but this should never fire, since we're never deleting threads except in Private::reset(), where we do remove them from allThreads), just in case. Saves ~0.5KiB in text size on optimized Linux AMD64 GCC 7.0 builds. Change-Id: I53a4d5ef2c204420f7c8852f1e72ab3d6ea43d08 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
7efd024b92
commit
a85b4d79db
@ -245,7 +245,8 @@ void QThreadPoolPrivate::startThread(QRunnable *runnable)
|
||||
{
|
||||
QScopedPointer <QThreadPoolThread> thread(new QThreadPoolThread(this));
|
||||
thread->setObjectName(QLatin1String("Thread (pooled)"));
|
||||
allThreads.insert(thread.data());
|
||||
Q_ASSERT(!allThreads.contains(thread.data())); // if this assert hits, we have an ABA problem (deleted threads don't get removed here)
|
||||
allThreads.append(thread.data());
|
||||
++activeThreads;
|
||||
|
||||
if (runnable->autoDelete())
|
||||
@ -265,7 +266,7 @@ void QThreadPoolPrivate::reset()
|
||||
|
||||
while (!allThreads.empty()) {
|
||||
// move the contents of the set out so that we can iterate without the lock
|
||||
QSet<QThreadPoolThread *> allThreadsCopy;
|
||||
QList<QThreadPoolThread *> allThreadsCopy;
|
||||
allThreadsCopy.swap(allThreads);
|
||||
locker.unlock();
|
||||
|
||||
|
@ -86,7 +86,7 @@ public:
|
||||
void stealAndRunRunnable(QRunnable *runnable);
|
||||
|
||||
mutable QMutex mutex;
|
||||
QSet<QThreadPoolThread *> allThreads;
|
||||
QList<QThreadPoolThread *> allThreads;
|
||||
QQueue<QThreadPoolThread *> waitingThreads;
|
||||
QQueue<QThreadPoolThread *> expiredThreads;
|
||||
QVector<QPair<QRunnable *, int> > queue;
|
||||
|
Loading…
x
Reference in New Issue
Block a user