From 8087ea67b1457db5da5a641628a11a84a3a119f2 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 10 Feb 2017 10:06:59 +0100 Subject: [PATCH] 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 --- .../corelib/thread/qthreadpool/tst_qthreadpool.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp b/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp index 49e1177e79..dede0be170 100644 --- a/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp +++ b/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp @@ -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()