tst_QThreadPool: simplify cancel()

Instead of allocating a statically-sized array on the heap,
use an automatic C array instead.

Replace some magic numbers with named constants.

Change-Id: I17d29a76a67c4a413453ac26a5dee8cd54a8a37d
Reviewed-by: David Faure <david.faure@kdab.com>
This commit is contained in:
Marc Mutz 2017-02-10 10:06:59 +01:00
parent dcf74bdec8
commit 8087ea67b1

View File

@ -981,12 +981,16 @@ void tst_QThreadPool::cancel()
count.ref();
}
};
typedef BlockingRunnable* BlockingRunnablePtr;
enum {
MaxThreadCount = 3,
OverProvisioning = 2,
runs = MaxThreadCount * OverProvisioning
};
QThreadPool threadPool;
threadPool.setMaxThreadCount(3);
int runs = 2 * threadPool.maxThreadCount();
BlockingRunnablePtr* runnables = new BlockingRunnablePtr[runs];
threadPool.setMaxThreadCount(MaxThreadCount);
BlockingRunnable *runnables[runs];
count.store(0);
QAtomicInt dtorCounter = 0;
QAtomicInt runCounter = 0;
@ -1009,7 +1013,6 @@ void tst_QThreadPool::cancel()
QCOMPARE(dtorCounter.load(), runs - 2);
delete runnables[0]; //if the pool deletes them then we'll get double-free crash
delete runnables[runs-1];
delete[] runnables;
}
void tst_QThreadPool::destroyingWaitsForTasksToFinish()