diff options
| author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-10-01 10:40:47 +0200 |
|---|---|---|
| committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-10-01 17:23:42 +0200 |
| commit | ecfda98d1f91c6a7da0d89826558d856cd88e670 (patch) | |
| tree | b230500224d56026ed7f0086822f7418930e92ea /src/corelib/thread/qthreadpool.cpp | |
| parent | 4940f6d04c1ca3f8782928ae6c1f08287a002d9c (diff) | |
Remove unnecessary ref-counting of QRunnable
It could never be higher than 1 anyway.
Change-Id: If33c7978a4397a08e9eb091926726725d8bd3ea6
Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
Diffstat (limited to 'src/corelib/thread/qthreadpool.cpp')
| -rw-r--r-- | src/corelib/thread/qthreadpool.cpp | 28 |
1 files changed, 3 insertions, 25 deletions
diff --git a/src/corelib/thread/qthreadpool.cpp b/src/corelib/thread/qthreadpool.cpp index 5765bf6b092..1c1bf38f9b3 100644 --- a/src/corelib/thread/qthreadpool.cpp +++ b/src/corelib/thread/qthreadpool.cpp @@ -88,9 +88,8 @@ void QThreadPoolThread::run() do { if (r) { + // If autoDelete() is false, r might already be deleted after run(), so check status now. const bool del = r->autoDelete(); - Q_ASSERT(!del || r->ref == 1); - // run the task locker.unlock(); @@ -330,7 +329,6 @@ void QThreadPoolPrivate::clear() while (!page->isFinished()) { QRunnable *r = page->pop(); if (r && r->autoDelete()) { - Q_ASSERT(r->ref == 1); locker.unlock(); delete r; locker.relock(); @@ -371,10 +369,6 @@ bool QThreadPool::tryTake(QRunnable *runnable) d->queue.removeOne(page); delete page; } - if (runnable->autoDelete()) { - Q_ASSERT(runnable->ref == 1); - --runnable->ref; // undo ++ref in start() - } return true; } } @@ -393,14 +387,13 @@ void QThreadPoolPrivate::stealAndRunRunnable(QRunnable *runnable) Q_Q(QThreadPool); if (!q->tryTake(runnable)) return; + // If autoDelete() is false, runnable might already be deleted after run(), so check status now. const bool del = runnable->autoDelete(); runnable->run(); - if (del) { - Q_ASSERT(runnable->ref == 0); // tryTake already deref'ed + if (del) delete runnable; - } } /*! @@ -508,10 +501,6 @@ void QThreadPool::start(QRunnable *runnable, int priority) Q_D(QThreadPool); QMutexLocker locker(&d->mutex); - if (runnable->autoDelete()) { - Q_ASSERT(runnable->ref == 0); - ++runnable->ref; - } if (!d->tryStart(runnable)) { d->enqueueTask(runnable, priority); @@ -558,22 +547,11 @@ bool QThreadPool::tryStart(QRunnable *runnable) if (!runnable) return false; - if (runnable->autoDelete()) { - Q_ASSERT(runnable->ref == 0); - ++runnable->ref; - } - Q_D(QThreadPool); QMutexLocker locker(&d->mutex); if (d->tryStart(runnable)) return true; - // Undo the reference above as we did not start the runnable and - // take over ownership. - if (runnable->autoDelete()) { - --runnable->ref; - Q_ASSERT(runnable->ref == 0); - } return false; } |
