Simplify list of workers in ThumbnailGenerator with unique_ptrs

This commit is contained in:
David Capello 2022-04-19 17:14:50 -03:00
parent f0a7d1faaa
commit 78ec753a3c
2 changed files with 7 additions and 10 deletions

View File

@ -250,10 +250,8 @@ bool ThumbnailGenerator::checkWorkers()
for (WorkerList::iterator
it=m_workers.begin(); it != m_workers.end(); ) {
Worker* worker = *it;
worker->updateProgress();
if (worker->isDone()) {
delete worker;
(*it)->updateProgress();
if ((*it)->isDone()) {
it = m_workers.erase(it);
}
else {
@ -334,7 +332,7 @@ void ThumbnailGenerator::stopAllWorkers()
}
base::scoped_lock hold(m_workersAccess);
for (auto worker : m_workers)
for (const auto& worker : m_workers)
worker->stop();
}
@ -342,9 +340,7 @@ void ThumbnailGenerator::startWorker()
{
base::scoped_lock hold(m_workersAccess);
if (m_workers.size() < m_maxWorkers) {
std::unique_ptr<Worker> worker(new Worker(m_remainingItems));
m_workers.push_back(worker.get());
worker.release();
m_workers.push_back(std::make_unique<Worker>(m_remainingItems));
}
}

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2019 Igara Studio S.A.
// Copyright (C) 2019-2022 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
@ -47,7 +47,8 @@ namespace app {
void startWorker();
class Worker;
typedef std::vector<Worker*> WorkerList;
using WorkerPtr = std::unique_ptr<Worker>;
using WorkerList = std::vector<WorkerPtr>;
struct Item {
IFileItem* fileitem;