diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-07-03 16:19:55 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-07-04 08:35:13 +0200 |
commit | 2ddddc46fdc3cf18cefcca29934eaab0544d2198 (patch) | |
tree | e79a7be6c614ed564ab7ebd13f948d28f738f015 /comphelper | |
parent | b0b4649690983143d88a4fae3c49f46ba2db3c51 (diff) |
Make ThreadPool::pushTask take param by std::unique_ptr
And fix leak in XclExpRowBuffer::Finalize, was not freeing the
synchronous task it creates
Change-Id: Id1e9ddb5d968e6b95d9d2b5ca0c9e50774580182
Reviewed-on: https://gerrit.libreoffice.org/56874
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'comphelper')
-rw-r--r-- | comphelper/source/misc/threadpool.cxx | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/comphelper/source/misc/threadpool.cxx b/comphelper/source/misc/threadpool.cxx index 23e363213206..a910ef08e138 100644 --- a/comphelper/source/misc/threadpool.cxx +++ b/comphelper/source/misc/threadpool.cxx @@ -62,12 +62,13 @@ public: while( !mpPool->mbTerminate ) { - ThreadTask *pTask = mpPool->popWorkLocked( aGuard, true ); + std::unique_ptr<ThreadTask> pTask = mpPool->popWorkLocked( aGuard, true ); if( pTask ) { aGuard.unlock(); - pTask->execAndDelete(); + pTask->exec(); + pTask.reset(); aGuard.lock(); } @@ -142,9 +143,9 @@ void ThreadPool::shutdownLocked(std::unique_lock<std::mutex>& aGuard) { if( maWorkers.empty() ) { // no threads at all -> execute the work in-line - ThreadTask *pTask; + std::unique_ptr<ThreadTask> pTask; while ( ( pTask = popWorkLocked(aGuard, false) ) ) - pTask->execAndDelete(); + pTask->exec(); } else { @@ -175,7 +176,7 @@ void ThreadPool::shutdownLocked(std::unique_lock<std::mutex>& aGuard) } } -void ThreadPool::pushTask( ThreadTask *pTask ) +void ThreadPool::pushTask( std::unique_ptr<ThreadTask> pTask ) { std::unique_lock< std::mutex > aGuard( maMutex ); @@ -188,18 +189,18 @@ void ThreadPool::pushTask( ThreadTask *pTask ) } pTask->mpTag->onTaskPushed(); - maTasks.insert( maTasks.begin(), pTask ); + maTasks.insert( maTasks.begin(), std::move(pTask) ); maTasksChanged.notify_one(); } -ThreadTask *ThreadPool::popWorkLocked( std::unique_lock< std::mutex > & rGuard, bool bWait ) +std::unique_ptr<ThreadTask> ThreadPool::popWorkLocked( std::unique_lock< std::mutex > & rGuard, bool bWait ) { do { if( !maTasks.empty() ) { - ThreadTask *pTask = maTasks.back(); + std::unique_ptr<ThreadTask> pTask = std::move(maTasks.back()); maTasks.pop_back(); return pTask; } @@ -223,10 +224,10 @@ void ThreadPool::waitUntilDone(const std::shared_ptr<ThreadTaskTag>& rTag) if( maWorkers.empty() ) { // no threads at all -> execute the work in-line - ThreadTask *pTask; + std::unique_ptr<ThreadTask> pTask; while (!rTag->isDone() && ( pTask = popWorkLocked(aGuard, false) ) ) - pTask->execAndDelete(); + pTask->exec(); } } @@ -256,7 +257,7 @@ ThreadTask::ThreadTask(const std::shared_ptr<ThreadTaskTag>& pTag) { } -void ThreadTask::execAndDelete() +void ThreadTask::exec() { std::shared_ptr<ThreadTaskTag> pTag(mpTag); try { @@ -271,7 +272,6 @@ void ThreadTask::execAndDelete() SAL_WARN("comphelper", "exception in thread worker while calling doWork(): " << e); } - delete this; pTag->onTaskWorkerDone(); } |