forked from qt-creator/qt-creator
Tasking::Async: Rename Async into AsyncTask
Rename Utils::AsyncTask into Utils::Async. Rename AsyncTaskBase into AsyncTask. Task-number: QTCREATORBUG-29102 Change-Id: I3aa24d84138c19922d4f61b1c9cf15bc8989f60e Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -115,7 +115,7 @@ const QFuture<T> &onFinished(const QFuture<T> &future, QObject *guard, Function
|
|||||||
return future;
|
return future;
|
||||||
}
|
}
|
||||||
|
|
||||||
class QTCREATOR_UTILS_EXPORT AsyncTaskBase : public QObject
|
class QTCREATOR_UTILS_EXPORT AsyncBase : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
@@ -126,15 +126,14 @@ signals:
|
|||||||
};
|
};
|
||||||
|
|
||||||
template <typename ResultType>
|
template <typename ResultType>
|
||||||
class AsyncTask : public AsyncTaskBase
|
class Async : public AsyncBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
AsyncTask() {
|
Async() {
|
||||||
connect(&m_watcher, &QFutureWatcherBase::finished, this, &AsyncTaskBase::done);
|
connect(&m_watcher, &QFutureWatcherBase::finished, this, &AsyncBase::done);
|
||||||
connect(&m_watcher, &QFutureWatcherBase::resultReadyAt,
|
connect(&m_watcher, &QFutureWatcherBase::resultReadyAt, this, &AsyncBase::resultReadyAt);
|
||||||
this, &AsyncTaskBase::resultReadyAt);
|
|
||||||
}
|
}
|
||||||
~AsyncTask()
|
~Async()
|
||||||
{
|
{
|
||||||
if (isDone())
|
if (isDone())
|
||||||
return;
|
return;
|
||||||
@@ -199,11 +198,11 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
template <typename ResultType>
|
template <typename ResultType>
|
||||||
class AsyncTaskAdapter : public Tasking::TaskAdapter<AsyncTask<ResultType>>
|
class AsyncTaskAdapter : public Tasking::TaskAdapter<Async<ResultType>>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
AsyncTaskAdapter() {
|
AsyncTaskAdapter() {
|
||||||
this->connect(this->task(), &AsyncTaskBase::done, this, [this] {
|
this->connect(this->task(), &AsyncBase::done, this, [this] {
|
||||||
emit this->done(!this->task()->isCanceled());
|
emit this->done(!this->task()->isCanceled());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -212,4 +211,4 @@ public:
|
|||||||
|
|
||||||
} // namespace Utils
|
} // namespace Utils
|
||||||
|
|
||||||
QTC_DECLARE_CUSTOM_TEMPLATE_TASK(Async, AsyncTaskAdapter);
|
QTC_DECLARE_CUSTOM_TEMPLATE_TASK(AsyncTask, AsyncTaskAdapter);
|
||||||
|
|||||||
@@ -96,14 +96,14 @@ private:
|
|||||||
return ProcessTask(setup);
|
return ProcessTask(setup);
|
||||||
}
|
}
|
||||||
TaskItem localTask() final {
|
TaskItem localTask() final {
|
||||||
const auto setup = [this](AsyncTask<QByteArray> &async) {
|
const auto setup = [this](Async<QByteArray> &async) {
|
||||||
async.setConcurrentCallData(localRead, m_filePath);
|
async.setConcurrentCallData(localRead, m_filePath);
|
||||||
AsyncTask<QByteArray> *asyncPtr = &async;
|
Async<QByteArray> *asyncPtr = &async;
|
||||||
connect(asyncPtr, &AsyncTaskBase::resultReadyAt, this, [=](int index) {
|
connect(asyncPtr, &AsyncBase::resultReadyAt, this, [=](int index) {
|
||||||
emit readyRead(asyncPtr->resultAt(index));
|
emit readyRead(asyncPtr->resultAt(index));
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
return Async<QByteArray>(setup);
|
return AsyncTask<QByteArray>(setup);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -267,16 +267,16 @@ private:
|
|||||||
return ProcessTask(setup, finalize, finalize);
|
return ProcessTask(setup, finalize, finalize);
|
||||||
}
|
}
|
||||||
TaskItem localTask() final {
|
TaskItem localTask() final {
|
||||||
const auto setup = [this](AsyncTask<void> &async) {
|
const auto setup = [this](Async<void> &async) {
|
||||||
m_writeBuffer = new WriteBuffer(isBuffered(), &async);
|
m_writeBuffer = new WriteBuffer(isBuffered(), &async);
|
||||||
async.setConcurrentCallData(localWrite, m_filePath, m_writeData, m_writeBuffer);
|
async.setConcurrentCallData(localWrite, m_filePath, m_writeData, m_writeBuffer);
|
||||||
emit started();
|
emit started();
|
||||||
};
|
};
|
||||||
const auto finalize = [this](const AsyncTask<void> &) {
|
const auto finalize = [this](const Async<void> &) {
|
||||||
delete m_writeBuffer;
|
delete m_writeBuffer;
|
||||||
m_writeBuffer = nullptr;
|
m_writeBuffer = nullptr;
|
||||||
};
|
};
|
||||||
return Async<void>(setup, finalize, finalize);
|
return AsyncTask<void>(setup, finalize, finalize);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isBuffered() const { return m_writeData.isEmpty(); }
|
bool isBuffered() const { return m_writeData.isEmpty(); }
|
||||||
@@ -437,10 +437,10 @@ private:
|
|||||||
return Writer(setup);
|
return Writer(setup);
|
||||||
}
|
}
|
||||||
TaskItem transferTask() {
|
TaskItem transferTask() {
|
||||||
const auto setup = [this](AsyncTask<void> &async) {
|
const auto setup = [this](Async<void> &async) {
|
||||||
async.setConcurrentCallData(transfer, m_source, m_destination);
|
async.setConcurrentCallData(transfer, m_source, m_destination);
|
||||||
};
|
};
|
||||||
return Async<void>(setup);
|
return AsyncTask<void>(setup);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -361,17 +361,17 @@ void TestCodeParser::scanForTests(const QSet<FilePath> &filePaths,
|
|||||||
|
|
||||||
QList<TaskItem> tasks{ParallelLimit(std::max(QThread::idealThreadCount() / 4, 1))};
|
QList<TaskItem> tasks{ParallelLimit(std::max(QThread::idealThreadCount() / 4, 1))};
|
||||||
for (const FilePath &file : filteredFiles) {
|
for (const FilePath &file : filteredFiles) {
|
||||||
const auto setup = [this, codeParsers, file](AsyncTask<TestParseResultPtr> &async) {
|
const auto setup = [this, codeParsers, file](Async<TestParseResultPtr> &async) {
|
||||||
async.setConcurrentCallData(parseFileForTests, codeParsers, file);
|
async.setConcurrentCallData(parseFileForTests, codeParsers, file);
|
||||||
async.setPriority(QThread::LowestPriority);
|
async.setPriority(QThread::LowestPriority);
|
||||||
async.setFutureSynchronizer(&m_futureSynchronizer);
|
async.setFutureSynchronizer(&m_futureSynchronizer);
|
||||||
};
|
};
|
||||||
const auto onDone = [this](const AsyncTask<TestParseResultPtr> &async) {
|
const auto onDone = [this](const Async<TestParseResultPtr> &async) {
|
||||||
const QList<TestParseResultPtr> results = async.results();
|
const QList<TestParseResultPtr> results = async.results();
|
||||||
for (const TestParseResultPtr &result : results)
|
for (const TestParseResultPtr &result : results)
|
||||||
emit testParseResultReady(result);
|
emit testParseResultReady(result);
|
||||||
};
|
};
|
||||||
tasks.append(Async<TestParseResultPtr>(setup, onDone));
|
tasks.append(AsyncTask<TestParseResultPtr>(setup, onDone));
|
||||||
}
|
}
|
||||||
m_taskTree.reset(new TaskTree{tasks});
|
m_taskTree.reset(new TaskTree{tasks});
|
||||||
const auto onDone = [this] { m_taskTree.release()->deleteLater(); onFinished(true); };
|
const auto onDone = [this] { m_taskTree.release()->deleteLater(); onFinished(true); };
|
||||||
|
|||||||
@@ -443,7 +443,7 @@ LocatorMatcherTask currentDocumentMatcher()
|
|||||||
*resultStorage = request.currentDocumentSymbolsData();
|
*resultStorage = request.currentDocumentSymbolsData();
|
||||||
};
|
};
|
||||||
|
|
||||||
const auto onFilterSetup = [=](AsyncTask<void> &async) {
|
const auto onFilterSetup = [=](Async<void> &async) {
|
||||||
async.setFutureSynchronizer(ExtensionSystem::PluginManager::futureSynchronizer());
|
async.setFutureSynchronizer(ExtensionSystem::PluginManager::futureSynchronizer());
|
||||||
async.setConcurrentCallData(filterCurrentResults, *storage, *resultStorage,
|
async.setConcurrentCallData(filterCurrentResults, *storage, *resultStorage,
|
||||||
TextDocument::currentTextDocument()->plainText());
|
TextDocument::currentTextDocument()->plainText());
|
||||||
@@ -452,7 +452,7 @@ LocatorMatcherTask currentDocumentMatcher()
|
|||||||
const Group root {
|
const Group root {
|
||||||
Storage(resultStorage),
|
Storage(resultStorage),
|
||||||
CurrentDocumentSymbolsRequest(onQuerySetup, onQueryDone),
|
CurrentDocumentSymbolsRequest(onQuerySetup, onQueryDone),
|
||||||
Async<void>(onFilterSetup)
|
AsyncTask<void>(onFilterSetup)
|
||||||
};
|
};
|
||||||
return {root, storage};
|
return {root, storage};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -180,7 +180,7 @@ LocatorMatcherTasks ActionsFilter::matchers()
|
|||||||
|
|
||||||
TreeStorage<LocatorStorage> storage;
|
TreeStorage<LocatorStorage> storage;
|
||||||
|
|
||||||
const auto onSetup = [this, storage](AsyncTask<void> &async) {
|
const auto onSetup = [this, storage](Async<void> &async) {
|
||||||
m_entries.clear();
|
m_entries.clear();
|
||||||
m_indexes.clear();
|
m_indexes.clear();
|
||||||
QList<const QMenu *> processedMenus;
|
QList<const QMenu *> processedMenus;
|
||||||
@@ -197,7 +197,7 @@ LocatorMatcherTasks ActionsFilter::matchers()
|
|||||||
return TaskAction::Continue;
|
return TaskAction::Continue;
|
||||||
};
|
};
|
||||||
|
|
||||||
return {{Async<void>(onSetup), storage}};
|
return {{AsyncTask<void>(onSetup), storage}};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -87,17 +87,17 @@ DirectoryFilter::DirectoryFilter(Id id)
|
|||||||
updateFileIterator();
|
updateFileIterator();
|
||||||
return TaskAction::StopWithDone; // Group stops, skips async task
|
return TaskAction::StopWithDone; // Group stops, skips async task
|
||||||
};
|
};
|
||||||
const auto asyncSetup = [this](AsyncTask<FilePaths> &async) {
|
const auto asyncSetup = [this](Async<FilePaths> &async) {
|
||||||
async.setConcurrentCallData(&refresh, m_directories, m_filters, m_exclusionFilters,
|
async.setConcurrentCallData(&refresh, m_directories, m_filters, m_exclusionFilters,
|
||||||
displayName());
|
displayName());
|
||||||
};
|
};
|
||||||
const auto asyncDone = [this](const AsyncTask<FilePaths> &async) {
|
const auto asyncDone = [this](const Async<FilePaths> &async) {
|
||||||
m_files = async.isResultAvailable() ? async.result() : FilePaths();
|
m_files = async.isResultAvailable() ? async.result() : FilePaths();
|
||||||
updateFileIterator();
|
updateFileIterator();
|
||||||
};
|
};
|
||||||
const Group root {
|
const Group root {
|
||||||
OnGroupSetup(groupSetup),
|
OnGroupSetup(groupSetup),
|
||||||
Async<FilePaths>(asyncSetup, asyncDone)
|
AsyncTask<FilePaths>(asyncSetup, asyncDone)
|
||||||
};
|
};
|
||||||
setRefreshRecipe(root);
|
setRefreshRecipe(root);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -323,7 +323,7 @@ LocatorMatcherTasks FileSystemFilter::matchers()
|
|||||||
|
|
||||||
TreeStorage<LocatorStorage> storage;
|
TreeStorage<LocatorStorage> storage;
|
||||||
|
|
||||||
const auto onSetup = [this, storage](AsyncTask<void> &async) {
|
const auto onSetup = [this, storage](Async<void> &async) {
|
||||||
async.setFutureSynchronizer(ExtensionSystem::PluginManager::futureSynchronizer());
|
async.setFutureSynchronizer(ExtensionSystem::PluginManager::futureSynchronizer());
|
||||||
async.setConcurrentCallData(matches,
|
async.setConcurrentCallData(matches,
|
||||||
*storage,
|
*storage,
|
||||||
@@ -332,7 +332,7 @@ LocatorMatcherTasks FileSystemFilter::matchers()
|
|||||||
m_includeHidden);
|
m_includeHidden);
|
||||||
};
|
};
|
||||||
|
|
||||||
return {{Async<void>(onSetup), storage}};
|
return {{AsyncTask<void>(onSetup), storage}};
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileSystemFilter::prepareSearch(const QString &entry)
|
void FileSystemFilter::prepareSearch(const QString &entry)
|
||||||
|
|||||||
@@ -1529,7 +1529,7 @@ LocatorMatcherTask LocatorFileCache::matcher() const
|
|||||||
TreeStorage<LocatorStorage> storage;
|
TreeStorage<LocatorStorage> storage;
|
||||||
std::weak_ptr<LocatorFileCachePrivate> weak = d;
|
std::weak_ptr<LocatorFileCachePrivate> weak = d;
|
||||||
|
|
||||||
const auto onSetup = [storage, weak](AsyncTask<LocatorFileCachePrivate> &async) {
|
const auto onSetup = [storage, weak](Async<LocatorFileCachePrivate> &async) {
|
||||||
auto that = weak.lock();
|
auto that = weak.lock();
|
||||||
if (!that) // LocatorMatcher is running after *this LocatorFileCache was destructed.
|
if (!that) // LocatorMatcher is running after *this LocatorFileCache was destructed.
|
||||||
return TaskAction::StopWithDone;
|
return TaskAction::StopWithDone;
|
||||||
@@ -1543,7 +1543,7 @@ LocatorMatcherTask LocatorFileCache::matcher() const
|
|||||||
async.setConcurrentCallData(&filter, *storage, *that);
|
async.setConcurrentCallData(&filter, *storage, *that);
|
||||||
return TaskAction::Continue;
|
return TaskAction::Continue;
|
||||||
};
|
};
|
||||||
const auto onDone = [weak](const AsyncTask<LocatorFileCachePrivate> &async) {
|
const auto onDone = [weak](const Async<LocatorFileCachePrivate> &async) {
|
||||||
auto that = weak.lock();
|
auto that = weak.lock();
|
||||||
if (!that)
|
if (!that)
|
||||||
return; // LocatorMatcherTask finished after *this LocatorFileCache was destructed.
|
return; // LocatorMatcherTask finished after *this LocatorFileCache was destructed.
|
||||||
@@ -1560,7 +1560,7 @@ LocatorMatcherTask LocatorFileCache::matcher() const
|
|||||||
that->update(async.result());
|
that->update(async.result());
|
||||||
};
|
};
|
||||||
|
|
||||||
return {Async<LocatorFileCachePrivate>(onSetup, onDone), storage};
|
return {AsyncTask<LocatorFileCachePrivate>(onSetup, onDone), storage};
|
||||||
}
|
}
|
||||||
|
|
||||||
} // Core
|
} // Core
|
||||||
|
|||||||
@@ -79,14 +79,14 @@ LocatorMatcherTasks OpenDocumentsFilter::matchers()
|
|||||||
|
|
||||||
TreeStorage<LocatorStorage> storage;
|
TreeStorage<LocatorStorage> storage;
|
||||||
|
|
||||||
const auto onSetup = [storage](AsyncTask<void> &async) {
|
const auto onSetup = [storage](Async<void> &async) {
|
||||||
const QList<Entry> editorsData = Utils::transform(DocumentModel::entries(),
|
const QList<Entry> editorsData = Utils::transform(DocumentModel::entries(),
|
||||||
[](const DocumentModel::Entry *e) { return Entry{e->filePath(), e->displayName()}; });
|
[](const DocumentModel::Entry *e) { return Entry{e->filePath(), e->displayName()}; });
|
||||||
async.setFutureSynchronizer(ExtensionSystem::PluginManager::futureSynchronizer());
|
async.setFutureSynchronizer(ExtensionSystem::PluginManager::futureSynchronizer());
|
||||||
async.setConcurrentCallData(matchEditors, *storage, editorsData);
|
async.setConcurrentCallData(matchEditors, *storage, editorsData);
|
||||||
};
|
};
|
||||||
|
|
||||||
return {{Async<void>(onSetup), storage}};
|
return {{AsyncTask<void>(onSetup), storage}};
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenDocumentsFilter::slotDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight,
|
void OpenDocumentsFilter::slotDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight,
|
||||||
|
|||||||
@@ -299,7 +299,7 @@ LocatorMatcherTasks SpotlightLocatorFilter::matchers()
|
|||||||
TreeStorage<LocatorStorage> storage;
|
TreeStorage<LocatorStorage> storage;
|
||||||
|
|
||||||
const auto onSetup = [storage, command = m_command, insensArgs = m_arguments,
|
const auto onSetup = [storage, command = m_command, insensArgs = m_arguments,
|
||||||
sensArgs = m_caseSensitiveArguments](AsyncTask<void> &async) {
|
sensArgs = m_caseSensitiveArguments](Async<void> &async) {
|
||||||
const Link link = Link::fromString(storage->input(), true);
|
const Link link = Link::fromString(storage->input(), true);
|
||||||
const FilePath input = link.targetFilePath;
|
const FilePath input = link.targetFilePath;
|
||||||
if (input.isEmpty())
|
if (input.isEmpty())
|
||||||
@@ -316,7 +316,7 @@ LocatorMatcherTasks SpotlightLocatorFilter::matchers()
|
|||||||
return TaskAction::Continue;
|
return TaskAction::Continue;
|
||||||
};
|
};
|
||||||
|
|
||||||
return {{Async<void>(onSetup), storage}};
|
return {{AsyncTask<void>(onSetup), storage}};
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpotlightLocatorFilter::prepareSearch(const QString &entry)
|
void SpotlightLocatorFilter::prepareSearch(const QString &entry)
|
||||||
|
|||||||
@@ -108,11 +108,11 @@ LocatorMatcherTask locatorMatcher(IndexItem::ItemType type, const EntryFromIndex
|
|||||||
|
|
||||||
TreeStorage<LocatorStorage> storage;
|
TreeStorage<LocatorStorage> storage;
|
||||||
|
|
||||||
const auto onSetup = [=](AsyncTask<void> &async) {
|
const auto onSetup = [=](Async<void> &async) {
|
||||||
async.setFutureSynchronizer(ExtensionSystem::PluginManager::futureSynchronizer());
|
async.setFutureSynchronizer(ExtensionSystem::PluginManager::futureSynchronizer());
|
||||||
async.setConcurrentCallData(matchesFor, *storage, type, converter);
|
async.setConcurrentCallData(matchesFor, *storage, type, converter);
|
||||||
};
|
};
|
||||||
return {Async<void>(onSetup), storage};
|
return {AsyncTask<void>(onSetup), storage};
|
||||||
}
|
}
|
||||||
|
|
||||||
LocatorMatcherTask allSymbolsMatcher()
|
LocatorMatcherTask allSymbolsMatcher()
|
||||||
@@ -304,11 +304,11 @@ LocatorMatcherTask currentDocumentMatcher()
|
|||||||
|
|
||||||
TreeStorage<LocatorStorage> storage;
|
TreeStorage<LocatorStorage> storage;
|
||||||
|
|
||||||
const auto onSetup = [=](AsyncTask<void> &async) {
|
const auto onSetup = [=](Async<void> &async) {
|
||||||
async.setFutureSynchronizer(ExtensionSystem::PluginManager::futureSynchronizer());
|
async.setFutureSynchronizer(ExtensionSystem::PluginManager::futureSynchronizer());
|
||||||
async.setConcurrentCallData(matchesForCurrentDocument, *storage, currentFileName());
|
async.setConcurrentCallData(matchesForCurrentDocument, *storage, currentFileName());
|
||||||
};
|
};
|
||||||
return {Async<void>(onSetup), storage};
|
return {AsyncTask<void>(onSetup), storage};
|
||||||
}
|
}
|
||||||
|
|
||||||
using MatcherCreator = std::function<Core::LocatorMatcherTask()>;
|
using MatcherCreator = std::function<Core::LocatorMatcherTask()>;
|
||||||
|
|||||||
@@ -58,16 +58,16 @@ void CppProjectUpdater::update(const ProjectUpdateInfo &projectUpdateInfo,
|
|||||||
ProjectInfo::ConstPtr projectInfo = nullptr;
|
ProjectInfo::ConstPtr projectInfo = nullptr;
|
||||||
};
|
};
|
||||||
const TreeStorage<UpdateStorage> storage;
|
const TreeStorage<UpdateStorage> storage;
|
||||||
const auto setupInfoGenerator = [=](AsyncTask<ProjectInfo::ConstPtr> &async) {
|
const auto setupInfoGenerator = [=](Async<ProjectInfo::ConstPtr> &async) {
|
||||||
async.setConcurrentCallData(infoGenerator);
|
async.setConcurrentCallData(infoGenerator);
|
||||||
async.setFutureSynchronizer(&m_futureSynchronizer);
|
async.setFutureSynchronizer(&m_futureSynchronizer);
|
||||||
};
|
};
|
||||||
const auto onInfoGeneratorDone = [=](const AsyncTask<ProjectInfo::ConstPtr> &async) {
|
const auto onInfoGeneratorDone = [=](const Async<ProjectInfo::ConstPtr> &async) {
|
||||||
if (async.isResultAvailable())
|
if (async.isResultAvailable())
|
||||||
storage->projectInfo = async.result();
|
storage->projectInfo = async.result();
|
||||||
};
|
};
|
||||||
QList<TaskItem> tasks{parallel};
|
QList<TaskItem> tasks{parallel};
|
||||||
tasks.append(Async<ProjectInfo::ConstPtr>(setupInfoGenerator, onInfoGeneratorDone));
|
tasks.append(AsyncTask<ProjectInfo::ConstPtr>(setupInfoGenerator, onInfoGeneratorDone));
|
||||||
for (QPointer<ExtraCompiler> compiler : compilers) {
|
for (QPointer<ExtraCompiler> compiler : compilers) {
|
||||||
if (compiler && compiler->isDirty())
|
if (compiler && compiler->isDirty())
|
||||||
tasks.append(compiler->compileFileItem());
|
tasks.append(compiler->compileFileItem());
|
||||||
|
|||||||
@@ -249,11 +249,11 @@ void AttachCoreDialog::accepted()
|
|||||||
|
|
||||||
const Group root = {
|
const Group root = {
|
||||||
parallel,
|
parallel,
|
||||||
Async<ResultType>{[=](auto &task) {
|
AsyncTask<ResultType>{[=](auto &task) {
|
||||||
task.setConcurrentCallData(copyFileAsync, this->coreFile());
|
task.setConcurrentCallData(copyFileAsync, this->coreFile());
|
||||||
},
|
},
|
||||||
[=](const auto &task) { d->coreFileResult = task.result(); }},
|
[=](const auto &task) { d->coreFileResult = task.result(); }},
|
||||||
Async<ResultType>{[=](auto &task) {
|
AsyncTask<ResultType>{[=](auto &task) {
|
||||||
task.setConcurrentCallData(copyFileAsync, this->symbolFile());
|
task.setConcurrentCallData(copyFileAsync, this->symbolFile());
|
||||||
},
|
},
|
||||||
[=](const auto &task) { d->symbolFileResult = task.result(); }},
|
[=](const auto &task) { d->symbolFileResult = task.result(); }},
|
||||||
|
|||||||
@@ -114,12 +114,12 @@ DiffFilesController::DiffFilesController(IDocument *document)
|
|||||||
const auto setupTree = [this, storage](TaskTree &taskTree) {
|
const auto setupTree = [this, storage](TaskTree &taskTree) {
|
||||||
QList<std::optional<FileData>> *outputList = storage.activeStorage();
|
QList<std::optional<FileData>> *outputList = storage.activeStorage();
|
||||||
|
|
||||||
const auto setupDiff = [this](AsyncTask<FileData> &async, const ReloadInput &reloadInput) {
|
const auto setupDiff = [this](Async<FileData> &async, const ReloadInput &reloadInput) {
|
||||||
async.setConcurrentCallData(
|
async.setConcurrentCallData(
|
||||||
DiffFile(ignoreWhitespace(), contextLineCount()), reloadInput);
|
DiffFile(ignoreWhitespace(), contextLineCount()), reloadInput);
|
||||||
async.setFutureSynchronizer(ExtensionSystem::PluginManager::futureSynchronizer());
|
async.setFutureSynchronizer(ExtensionSystem::PluginManager::futureSynchronizer());
|
||||||
};
|
};
|
||||||
const auto onDiffDone = [outputList](const AsyncTask<FileData> &async, int i) {
|
const auto onDiffDone = [outputList](const Async<FileData> &async, int i) {
|
||||||
if (async.isResultAvailable())
|
if (async.isResultAvailable())
|
||||||
(*outputList)[i] = async.result();
|
(*outputList)[i] = async.result();
|
||||||
};
|
};
|
||||||
@@ -130,7 +130,7 @@ DiffFilesController::DiffFilesController(IDocument *document)
|
|||||||
using namespace std::placeholders;
|
using namespace std::placeholders;
|
||||||
QList<TaskItem> tasks {parallel, optional};
|
QList<TaskItem> tasks {parallel, optional};
|
||||||
for (int i = 0; i < inputList.size(); ++i) {
|
for (int i = 0; i < inputList.size(); ++i) {
|
||||||
tasks.append(Async<FileData>(std::bind(setupDiff, _1, inputList.at(i)),
|
tasks.append(AsyncTask<FileData>(std::bind(setupDiff, _1, inputList.at(i)),
|
||||||
std::bind(onDiffDone, _1, i)));
|
std::bind(onDiffDone, _1, i)));
|
||||||
}
|
}
|
||||||
taskTree.setupRoot(tasks);
|
taskTree.setupRoot(tasks);
|
||||||
|
|||||||
@@ -869,11 +869,11 @@ void SideBySideDiffEditorWidget::restoreState()
|
|||||||
|
|
||||||
void SideBySideDiffEditorWidget::showDiff()
|
void SideBySideDiffEditorWidget::showDiff()
|
||||||
{
|
{
|
||||||
m_asyncTask.reset(new AsyncTask<SideBySideShowResults>());
|
m_asyncTask.reset(new Async<SideBySideShowResults>());
|
||||||
m_asyncTask->setFutureSynchronizer(ExtensionSystem::PluginManager::futureSynchronizer());
|
m_asyncTask->setFutureSynchronizer(ExtensionSystem::PluginManager::futureSynchronizer());
|
||||||
m_controller.setBusyShowing(true);
|
m_controller.setBusyShowing(true);
|
||||||
|
|
||||||
connect(m_asyncTask.get(), &AsyncTaskBase::done, this, [this] {
|
connect(m_asyncTask.get(), &AsyncBase::done, this, [this] {
|
||||||
if (m_asyncTask->isCanceled() || !m_asyncTask->isResultAvailable()) {
|
if (m_asyncTask->isCanceled() || !m_asyncTask->isResultAvailable()) {
|
||||||
for (SideDiffEditorWidget *editor : m_editor)
|
for (SideDiffEditorWidget *editor : m_editor)
|
||||||
editor->clearAll(Tr::tr("Retrieving data failed."));
|
editor->clearAll(Tr::tr("Retrieving data failed."));
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ class TextEditorWidget;
|
|||||||
|
|
||||||
namespace Utils {
|
namespace Utils {
|
||||||
template <typename R>
|
template <typename R>
|
||||||
class AsyncTask;
|
class Async;
|
||||||
}
|
}
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
@@ -141,7 +141,7 @@ private:
|
|||||||
|
|
||||||
bool m_horizontalSync = false;
|
bool m_horizontalSync = false;
|
||||||
|
|
||||||
std::unique_ptr<Utils::AsyncTask<SideBySideShowResults>> m_asyncTask;
|
std::unique_ptr<Utils::Async<SideBySideShowResults>> m_asyncTask;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
|||||||
@@ -452,10 +452,10 @@ void UnifiedDiffEditorWidget::showDiff()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_asyncTask.reset(new AsyncTask<UnifiedShowResult>());
|
m_asyncTask.reset(new Async<UnifiedShowResult>());
|
||||||
m_asyncTask->setFutureSynchronizer(ExtensionSystem::PluginManager::futureSynchronizer());
|
m_asyncTask->setFutureSynchronizer(ExtensionSystem::PluginManager::futureSynchronizer());
|
||||||
m_controller.setBusyShowing(true);
|
m_controller.setBusyShowing(true);
|
||||||
connect(m_asyncTask.get(), &AsyncTaskBase::done, this, [this] {
|
connect(m_asyncTask.get(), &AsyncBase::done, this, [this] {
|
||||||
if (m_asyncTask->isCanceled() || !m_asyncTask->isResultAvailable()) {
|
if (m_asyncTask->isCanceled() || !m_asyncTask->isResultAvailable()) {
|
||||||
setPlainText(Tr::tr("Retrieving data failed."));
|
setPlainText(Tr::tr("Retrieving data failed."));
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ namespace TextEditor { class FontSettings; }
|
|||||||
|
|
||||||
namespace Utils {
|
namespace Utils {
|
||||||
template <typename R>
|
template <typename R>
|
||||||
class AsyncTask;
|
class Async;
|
||||||
}
|
}
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
@@ -112,7 +112,7 @@ private:
|
|||||||
DiffEditorWidgetController m_controller;
|
DiffEditorWidgetController m_controller;
|
||||||
QByteArray m_state;
|
QByteArray m_state;
|
||||||
|
|
||||||
std::unique_ptr<Utils::AsyncTask<UnifiedShowResult>> m_asyncTask;
|
std::unique_ptr<Utils::Async<UnifiedShowResult>> m_asyncTask;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ LocatorMatcherTasks HelpIndexFilter::matchers()
|
|||||||
|
|
||||||
TreeStorage<LocatorStorage> storage;
|
TreeStorage<LocatorStorage> storage;
|
||||||
|
|
||||||
const auto onSetup = [this, storage](AsyncTask<QStringList> &async) {
|
const auto onSetup = [this, storage](Async<QStringList> &async) {
|
||||||
if (m_needsUpdate) {
|
if (m_needsUpdate) {
|
||||||
m_needsUpdate = false;
|
m_needsUpdate = false;
|
||||||
LocalHelpManager::setupGuiHelpEngine();
|
LocalHelpManager::setupGuiHelpEngine();
|
||||||
@@ -100,14 +100,14 @@ LocatorMatcherTasks HelpIndexFilter::matchers()
|
|||||||
async.setFutureSynchronizer(ExtensionSystem::PluginManager::futureSynchronizer());
|
async.setFutureSynchronizer(ExtensionSystem::PluginManager::futureSynchronizer());
|
||||||
async.setConcurrentCallData(matches, *storage, cache, m_icon);
|
async.setConcurrentCallData(matches, *storage, cache, m_icon);
|
||||||
};
|
};
|
||||||
const auto onDone = [this, storage](const AsyncTask<QStringList> &async) {
|
const auto onDone = [this, storage](const Async<QStringList> &async) {
|
||||||
if (async.isResultAvailable()) {
|
if (async.isResultAvailable()) {
|
||||||
m_lastIndicesCache = async.result();
|
m_lastIndicesCache = async.result();
|
||||||
m_lastEntry = storage->input();
|
m_lastEntry = storage->input();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return {{Async<QStringList>(onSetup, onDone), storage}};
|
return {{AsyncTask<QStringList>(onSetup, onDone), storage}};
|
||||||
}
|
}
|
||||||
|
|
||||||
void HelpIndexFilter::prepareSearch(const QString &entry)
|
void HelpIndexFilter::prepareSearch(const QString &entry)
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ LocatorMatcherTask locatorMatcher(Client *client, int maxResultCount,
|
|||||||
*resultStorage = result->toList();
|
*resultStorage = result->toList();
|
||||||
};
|
};
|
||||||
|
|
||||||
const auto onFilterSetup = [=](AsyncTask<void> &async) {
|
const auto onFilterSetup = [=](Async<void> &async) {
|
||||||
const QList<SymbolInformation> results = *resultStorage;
|
const QList<SymbolInformation> results = *resultStorage;
|
||||||
if (results.isEmpty())
|
if (results.isEmpty())
|
||||||
return TaskAction::StopWithDone;
|
return TaskAction::StopWithDone;
|
||||||
@@ -87,7 +87,7 @@ LocatorMatcherTask locatorMatcher(Client *client, int maxResultCount,
|
|||||||
const Group root {
|
const Group root {
|
||||||
Storage(resultStorage),
|
Storage(resultStorage),
|
||||||
SymbolRequest(onQuerySetup, onQueryDone),
|
SymbolRequest(onQuerySetup, onQueryDone),
|
||||||
Async<void>(onFilterSetup)
|
AsyncTask<void>(onFilterSetup)
|
||||||
};
|
};
|
||||||
return {root, storage};
|
return {root, storage};
|
||||||
}
|
}
|
||||||
@@ -138,7 +138,7 @@ LocatorMatcherTask currentDocumentMatcher()
|
|||||||
*resultStorage = request.currentDocumentSymbolsData();
|
*resultStorage = request.currentDocumentSymbolsData();
|
||||||
};
|
};
|
||||||
|
|
||||||
const auto onFilterSetup = [=](AsyncTask<void> &async) {
|
const auto onFilterSetup = [=](Async<void> &async) {
|
||||||
async.setFutureSynchronizer(ExtensionSystem::PluginManager::futureSynchronizer());
|
async.setFutureSynchronizer(ExtensionSystem::PluginManager::futureSynchronizer());
|
||||||
async.setConcurrentCallData(filterCurrentResults, *storage, *resultStorage);
|
async.setConcurrentCallData(filterCurrentResults, *storage, *resultStorage);
|
||||||
};
|
};
|
||||||
@@ -146,7 +146,7 @@ LocatorMatcherTask currentDocumentMatcher()
|
|||||||
const Group root {
|
const Group root {
|
||||||
Storage(resultStorage),
|
Storage(resultStorage),
|
||||||
CurrentDocumentSymbolsRequest(onQuerySetup, onQueryDone),
|
CurrentDocumentSymbolsRequest(onQuerySetup, onQueryDone),
|
||||||
Async<void>(onFilterSetup)
|
AsyncTask<void>(onFilterSetup)
|
||||||
};
|
};
|
||||||
return {root, storage};
|
return {root, storage};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -327,14 +327,14 @@ ProcessExtraCompiler::ProcessExtraCompiler(const Project *project, const FilePat
|
|||||||
|
|
||||||
Tasking::TaskItem ProcessExtraCompiler::taskItemImpl(const ContentProvider &provider)
|
Tasking::TaskItem ProcessExtraCompiler::taskItemImpl(const ContentProvider &provider)
|
||||||
{
|
{
|
||||||
const auto setupTask = [=](AsyncTask<FileNameToContentsHash> &async) {
|
const auto setupTask = [=](Async<FileNameToContentsHash> &async) {
|
||||||
async.setThreadPool(extraCompilerThreadPool());
|
async.setThreadPool(extraCompilerThreadPool());
|
||||||
// The passed synchronizer has cancelOnWait set to true by default.
|
// The passed synchronizer has cancelOnWait set to true by default.
|
||||||
async.setFutureSynchronizer(ExtensionSystem::PluginManager::futureSynchronizer());
|
async.setFutureSynchronizer(ExtensionSystem::PluginManager::futureSynchronizer());
|
||||||
async.setConcurrentCallData(&ProcessExtraCompiler::runInThread, this, command(),
|
async.setConcurrentCallData(&ProcessExtraCompiler::runInThread, this, command(),
|
||||||
workingDirectory(), arguments(), provider, buildEnvironment());
|
workingDirectory(), arguments(), provider, buildEnvironment());
|
||||||
};
|
};
|
||||||
const auto taskDone = [=](const AsyncTask<FileNameToContentsHash> &async) {
|
const auto taskDone = [=](const Async<FileNameToContentsHash> &async) {
|
||||||
if (!async.isResultAvailable())
|
if (!async.isResultAvailable())
|
||||||
return;
|
return;
|
||||||
const FileNameToContentsHash data = async.result();
|
const FileNameToContentsHash data = async.result();
|
||||||
@@ -344,7 +344,7 @@ Tasking::TaskItem ProcessExtraCompiler::taskItemImpl(const ContentProvider &prov
|
|||||||
setContent(it.key(), it.value());
|
setContent(it.key(), it.value());
|
||||||
updateCompileTime();
|
updateCompileTime();
|
||||||
};
|
};
|
||||||
return Tasking::Async<FileNameToContentsHash>(setupTask, taskDone);
|
return Tasking::AsyncTask<FileNameToContentsHash>(setupTask, taskDone);
|
||||||
}
|
}
|
||||||
|
|
||||||
FilePath ProcessExtraCompiler::workingDirectory() const
|
FilePath ProcessExtraCompiler::workingDirectory() const
|
||||||
|
|||||||
@@ -82,12 +82,12 @@ LocatorMatcherTasks FunctionFilter::matchers()
|
|||||||
|
|
||||||
TreeStorage<LocatorStorage> storage;
|
TreeStorage<LocatorStorage> storage;
|
||||||
|
|
||||||
const auto onSetup = [storage, entries = m_data->entries()](AsyncTask<void> &async) {
|
const auto onSetup = [storage, entries = m_data->entries()](Async<void> &async) {
|
||||||
async.setFutureSynchronizer(ExtensionSystem::PluginManager::futureSynchronizer());
|
async.setFutureSynchronizer(ExtensionSystem::PluginManager::futureSynchronizer());
|
||||||
async.setConcurrentCallData(matches, *storage, entries);
|
async.setConcurrentCallData(matches, *storage, entries);
|
||||||
};
|
};
|
||||||
|
|
||||||
return {{Async<void>(onSetup), storage}};
|
return {{AsyncTask<void>(onSetup), storage}};
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<LocatorFilterEntry> FunctionFilter::matchesFor(QFutureInterface<LocatorFilterEntry> &future,
|
QList<LocatorFilterEntry> FunctionFilter::matchesFor(QFutureInterface<LocatorFilterEntry> &future,
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ Tasking::TaskItem VcsBaseDiffEditorController::postProcessTask()
|
|||||||
{
|
{
|
||||||
using namespace Tasking;
|
using namespace Tasking;
|
||||||
|
|
||||||
const auto setupDiffProcessor = [this](AsyncTask<QList<FileData>> &async) {
|
const auto setupDiffProcessor = [this](Async<QList<FileData>> &async) {
|
||||||
const QString *storage = inputStorage().activeStorage();
|
const QString *storage = inputStorage().activeStorage();
|
||||||
QTC_ASSERT(storage, qWarning("Using postProcessTask() requires putting inputStorage() "
|
QTC_ASSERT(storage, qWarning("Using postProcessTask() requires putting inputStorage() "
|
||||||
"into task tree's root group."));
|
"into task tree's root group."));
|
||||||
@@ -56,14 +56,14 @@ Tasking::TaskItem VcsBaseDiffEditorController::postProcessTask()
|
|||||||
async.setFutureSynchronizer(ExtensionSystem::PluginManager::futureSynchronizer());
|
async.setFutureSynchronizer(ExtensionSystem::PluginManager::futureSynchronizer());
|
||||||
async.setConcurrentCallData(&DiffUtils::readPatchWithPromise, inputData);
|
async.setConcurrentCallData(&DiffUtils::readPatchWithPromise, inputData);
|
||||||
};
|
};
|
||||||
const auto onDiffProcessorDone = [this](const AsyncTask<QList<FileData>> &async) {
|
const auto onDiffProcessorDone = [this](const Async<QList<FileData>> &async) {
|
||||||
setDiffFiles(async.isResultAvailable() ? async.result() : QList<FileData>());
|
setDiffFiles(async.isResultAvailable() ? async.result() : QList<FileData>());
|
||||||
// TODO: We should set the right starting line here
|
// TODO: We should set the right starting line here
|
||||||
};
|
};
|
||||||
const auto onDiffProcessorError = [this](const AsyncTask<QList<FileData>> &) {
|
const auto onDiffProcessorError = [this](const Async<QList<FileData>> &) {
|
||||||
setDiffFiles({});
|
setDiffFiles({});
|
||||||
};
|
};
|
||||||
return Async<QList<FileData>>(setupDiffProcessor, onDiffProcessorDone, onDiffProcessorError);
|
return AsyncTask<QList<FileData>>(setupDiffProcessor, onDiffProcessorDone, onDiffProcessorError);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VcsBaseDiffEditorController::setupCommand(QtcProcess &process, const QStringList &args) const
|
void VcsBaseDiffEditorController::setupCommand(QtcProcess &process, const QStringList &args) const
|
||||||
|
|||||||
@@ -123,9 +123,9 @@ struct ConcurrentResultType<Function, Args...>
|
|||||||
|
|
||||||
template <typename Function, typename ...Args,
|
template <typename Function, typename ...Args,
|
||||||
typename ResultType = typename ConcurrentResultType<Function, Args...>::Type>
|
typename ResultType = typename ConcurrentResultType<Function, Args...>::Type>
|
||||||
std::shared_ptr<AsyncTask<ResultType>> createAsyncTask(Function &&function, Args &&...args)
|
std::shared_ptr<Async<ResultType>> createAsyncTask(Function &&function, Args &&...args)
|
||||||
{
|
{
|
||||||
auto asyncTask = std::make_shared<AsyncTask<ResultType>>();
|
auto asyncTask = std::make_shared<Async<ResultType>>();
|
||||||
asyncTask->setConcurrentCallData(std::forward<Function>(function), std::forward<Args>(args)...);
|
asyncTask->setConcurrentCallData(std::forward<Function>(function), std::forward<Args>(args)...);
|
||||||
asyncTask->start();
|
asyncTask->start();
|
||||||
return asyncTask;
|
return asyncTask;
|
||||||
@@ -402,7 +402,7 @@ void tst_AsyncTask::futureSynchonizer()
|
|||||||
FutureSynchronizer synchronizer;
|
FutureSynchronizer synchronizer;
|
||||||
synchronizer.setCancelOnWait(false);
|
synchronizer.setCancelOnWait(false);
|
||||||
{
|
{
|
||||||
AsyncTask<int> task;
|
Async<int> task;
|
||||||
task.setConcurrentCallData(lambda);
|
task.setConcurrentCallData(lambda);
|
||||||
task.setFutureSynchronizer(&synchronizer);
|
task.setFutureSynchronizer(&synchronizer);
|
||||||
task.start();
|
task.start();
|
||||||
@@ -424,18 +424,18 @@ void tst_AsyncTask::taskTree()
|
|||||||
|
|
||||||
int value = 1;
|
int value = 1;
|
||||||
|
|
||||||
const auto setupIntAsync = [&](AsyncTask<int> &task) {
|
const auto setupIntAsync = [&](Async<int> &task) {
|
||||||
task.setConcurrentCallData(multiplyBy2, value);
|
task.setConcurrentCallData(multiplyBy2, value);
|
||||||
};
|
};
|
||||||
const auto handleIntAsync = [&](const AsyncTask<int> &task) {
|
const auto handleIntAsync = [&](const Async<int> &task) {
|
||||||
value = task.result();
|
value = task.result();
|
||||||
};
|
};
|
||||||
|
|
||||||
const Group root {
|
const Group root {
|
||||||
Async<int>(setupIntAsync, handleIntAsync),
|
AsyncTask<int>(setupIntAsync, handleIntAsync),
|
||||||
Async<int>(setupIntAsync, handleIntAsync),
|
AsyncTask<int>(setupIntAsync, handleIntAsync),
|
||||||
Async<int>(setupIntAsync, handleIntAsync),
|
AsyncTask<int>(setupIntAsync, handleIntAsync),
|
||||||
Async<int>(setupIntAsync, handleIntAsync),
|
AsyncTask<int>(setupIntAsync, handleIntAsync),
|
||||||
};
|
};
|
||||||
|
|
||||||
TaskTree tree(root);
|
TaskTree tree(root);
|
||||||
@@ -473,17 +473,17 @@ void tst_AsyncTask::mapReduce_data()
|
|||||||
s_sum = 0;
|
s_sum = 0;
|
||||||
s_results.append(s_sum);
|
s_results.append(s_sum);
|
||||||
};
|
};
|
||||||
const auto setupAsync = [](AsyncTask<int> &task, int input) {
|
const auto setupAsync = [](Async<int> &task, int input) {
|
||||||
task.setConcurrentCallData(returnxx, input);
|
task.setConcurrentCallData(returnxx, input);
|
||||||
};
|
};
|
||||||
const auto setupAsyncWithFI = [](AsyncTask<int> &task, int input) {
|
const auto setupAsyncWithFI = [](Async<int> &task, int input) {
|
||||||
task.setConcurrentCallData(returnxxWithPromise, input);
|
task.setConcurrentCallData(returnxxWithPromise, input);
|
||||||
};
|
};
|
||||||
const auto setupAsyncWithTP = [this](AsyncTask<int> &task, int input) {
|
const auto setupAsyncWithTP = [this](Async<int> &task, int input) {
|
||||||
task.setConcurrentCallData(returnxx, input);
|
task.setConcurrentCallData(returnxx, input);
|
||||||
task.setThreadPool(&m_threadPool);
|
task.setThreadPool(&m_threadPool);
|
||||||
};
|
};
|
||||||
const auto handleAsync = [](const AsyncTask<int> &task) {
|
const auto handleAsync = [](const Async<int> &task) {
|
||||||
s_sum += task.result();
|
s_sum += task.result();
|
||||||
s_results.append(task.result());
|
s_results.append(task.result());
|
||||||
};
|
};
|
||||||
@@ -500,7 +500,7 @@ void tst_AsyncTask::mapReduce_data()
|
|||||||
using namespace Tasking;
|
using namespace Tasking;
|
||||||
using namespace std::placeholders;
|
using namespace std::placeholders;
|
||||||
|
|
||||||
using SetupHandler = std::function<void(AsyncTask<int> &task, int input)>;
|
using SetupHandler = std::function<void(Async<int> &task, int input)>;
|
||||||
using DoneHandler = std::function<void()>;
|
using DoneHandler = std::function<void()>;
|
||||||
|
|
||||||
const auto createTask = [=](const TaskItem &executeMode,
|
const auto createTask = [=](const TaskItem &executeMode,
|
||||||
@@ -509,11 +509,11 @@ void tst_AsyncTask::mapReduce_data()
|
|||||||
return Group {
|
return Group {
|
||||||
executeMode,
|
executeMode,
|
||||||
OnGroupSetup(initTree),
|
OnGroupSetup(initTree),
|
||||||
Async<int>(std::bind(setupHandler, _1, 1), handleAsync),
|
AsyncTask<int>(std::bind(setupHandler, _1, 1), handleAsync),
|
||||||
Async<int>(std::bind(setupHandler, _1, 2), handleAsync),
|
AsyncTask<int>(std::bind(setupHandler, _1, 2), handleAsync),
|
||||||
Async<int>(std::bind(setupHandler, _1, 3), handleAsync),
|
AsyncTask<int>(std::bind(setupHandler, _1, 3), handleAsync),
|
||||||
Async<int>(std::bind(setupHandler, _1, 4), handleAsync),
|
AsyncTask<int>(std::bind(setupHandler, _1, 4), handleAsync),
|
||||||
Async<int>(std::bind(setupHandler, _1, 5), handleAsync),
|
AsyncTask<int>(std::bind(setupHandler, _1, 5), handleAsync),
|
||||||
OnGroupDone(doneHandler)
|
OnGroupDone(doneHandler)
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@@ -535,34 +535,34 @@ void tst_AsyncTask::mapReduce_data()
|
|||||||
QTest::newRow("SequentialWithFutureInterface") << sequentialRootWithFI << defaultSum << defaultResult;
|
QTest::newRow("SequentialWithFutureInterface") << sequentialRootWithFI << defaultSum << defaultResult;
|
||||||
QTest::newRow("SequentialWithThreadPool") << sequentialRootWithTP << defaultSum << defaultResult;
|
QTest::newRow("SequentialWithThreadPool") << sequentialRootWithTP << defaultSum << defaultResult;
|
||||||
|
|
||||||
const auto setupSimpleAsync = [](AsyncTask<int> &task, int input) {
|
const auto setupSimpleAsync = [](Async<int> &task, int input) {
|
||||||
task.setConcurrentCallData([](int input) { return input * 2; }, input);
|
task.setConcurrentCallData([](int input) { return input * 2; }, input);
|
||||||
};
|
};
|
||||||
const auto handleSimpleAsync = [](const AsyncTask<int> &task) {
|
const auto handleSimpleAsync = [](const Async<int> &task) {
|
||||||
s_sum += task.result() / 4.;
|
s_sum += task.result() / 4.;
|
||||||
s_results.append(s_sum);
|
s_results.append(s_sum);
|
||||||
};
|
};
|
||||||
const Group simpleRoot = {
|
const Group simpleRoot = {
|
||||||
sequential,
|
sequential,
|
||||||
OnGroupSetup([] { s_sum = 0; }),
|
OnGroupSetup([] { s_sum = 0; }),
|
||||||
Async<int>(std::bind(setupSimpleAsync, _1, 1), handleSimpleAsync),
|
AsyncTask<int>(std::bind(setupSimpleAsync, _1, 1), handleSimpleAsync),
|
||||||
Async<int>(std::bind(setupSimpleAsync, _1, 2), handleSimpleAsync),
|
AsyncTask<int>(std::bind(setupSimpleAsync, _1, 2), handleSimpleAsync),
|
||||||
Async<int>(std::bind(setupSimpleAsync, _1, 3), handleSimpleAsync)
|
AsyncTask<int>(std::bind(setupSimpleAsync, _1, 3), handleSimpleAsync)
|
||||||
};
|
};
|
||||||
QTest::newRow("Simple") << simpleRoot << 3.0 << QList<double>({.5, 1.5, 3.});
|
QTest::newRow("Simple") << simpleRoot << 3.0 << QList<double>({.5, 1.5, 3.});
|
||||||
|
|
||||||
const auto setupStringAsync = [](AsyncTask<int> &task, const QString &input) {
|
const auto setupStringAsync = [](Async<int> &task, const QString &input) {
|
||||||
task.setConcurrentCallData([](const QString &input) -> int { return input.size(); }, input);
|
task.setConcurrentCallData([](const QString &input) -> int { return input.size(); }, input);
|
||||||
};
|
};
|
||||||
const auto handleStringAsync = [](const AsyncTask<int> &task) {
|
const auto handleStringAsync = [](const Async<int> &task) {
|
||||||
s_sum /= task.result();
|
s_sum /= task.result();
|
||||||
};
|
};
|
||||||
const Group stringRoot = {
|
const Group stringRoot = {
|
||||||
parallel,
|
parallel,
|
||||||
OnGroupSetup([] { s_sum = 90.0; }),
|
OnGroupSetup([] { s_sum = 90.0; }),
|
||||||
Async<int>(std::bind(setupStringAsync, _1, "blubb"), handleStringAsync),
|
AsyncTask<int>(std::bind(setupStringAsync, _1, "blubb"), handleStringAsync),
|
||||||
Async<int>(std::bind(setupStringAsync, _1, "foo"), handleStringAsync),
|
AsyncTask<int>(std::bind(setupStringAsync, _1, "foo"), handleStringAsync),
|
||||||
Async<int>(std::bind(setupStringAsync, _1, "blah"), handleStringAsync)
|
AsyncTask<int>(std::bind(setupStringAsync, _1, "blah"), handleStringAsync)
|
||||||
};
|
};
|
||||||
QTest::newRow("String") << stringRoot << 1.5 << QList<double>({});
|
QTest::newRow("String") << stringRoot << 1.5 << QList<double>({});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,8 +13,8 @@ using namespace std::literals::chrono_literals;
|
|||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
using namespace Utils::Tasking;
|
using namespace Utils::Tasking;
|
||||||
|
|
||||||
using TestTask = AsyncTask<void>;
|
using TestTask = Async<void>;
|
||||||
using Test = Async<void>;
|
using Test = AsyncTask<void>;
|
||||||
|
|
||||||
enum class Handler {
|
enum class Handler {
|
||||||
Setup,
|
Setup,
|
||||||
@@ -198,7 +198,7 @@ template <typename SharedBarrierType>
|
|||||||
auto setupBarrierAdvance(const TreeStorage<CustomStorage> &storage,
|
auto setupBarrierAdvance(const TreeStorage<CustomStorage> &storage,
|
||||||
const SharedBarrierType &barrier, int taskId)
|
const SharedBarrierType &barrier, int taskId)
|
||||||
{
|
{
|
||||||
return [storage, barrier, taskId](AsyncTask<bool> &async) {
|
return [storage, barrier, taskId](Async<bool> &async) {
|
||||||
async.setFutureSynchronizer(s_futureSynchronizer);
|
async.setFutureSynchronizer(s_futureSynchronizer);
|
||||||
async.setConcurrentCallData(reportAndSleep);
|
async.setConcurrentCallData(reportAndSleep);
|
||||||
async.setProperty(s_taskIdProperty, taskId);
|
async.setProperty(s_taskIdProperty, taskId);
|
||||||
@@ -1213,7 +1213,7 @@ void tst_TaskTree::testTree_data()
|
|||||||
Storage(storage),
|
Storage(storage),
|
||||||
Storage(barrier),
|
Storage(barrier),
|
||||||
sequential,
|
sequential,
|
||||||
Async<bool>(setupBarrierAdvance(storage, barrier, 1)),
|
AsyncTask<bool>(setupBarrierAdvance(storage, barrier, 1)),
|
||||||
Group {
|
Group {
|
||||||
OnGroupSetup(groupSetup(2)),
|
OnGroupSetup(groupSetup(2)),
|
||||||
WaitForBarrier(barrier),
|
WaitForBarrier(barrier),
|
||||||
@@ -1236,7 +1236,7 @@ void tst_TaskTree::testTree_data()
|
|||||||
Storage(storage),
|
Storage(storage),
|
||||||
Storage(barrier),
|
Storage(barrier),
|
||||||
parallel,
|
parallel,
|
||||||
Async<bool>(setupBarrierAdvance(storage, barrier, 1)),
|
AsyncTask<bool>(setupBarrierAdvance(storage, barrier, 1)),
|
||||||
Group {
|
Group {
|
||||||
OnGroupSetup(groupSetup(2)),
|
OnGroupSetup(groupSetup(2)),
|
||||||
WaitForBarrier(barrier),
|
WaitForBarrier(barrier),
|
||||||
@@ -1272,7 +1272,7 @@ void tst_TaskTree::testTree_data()
|
|||||||
Test(setupTask(2)),
|
Test(setupTask(2)),
|
||||||
Test(setupTask(3))
|
Test(setupTask(3))
|
||||||
},
|
},
|
||||||
Async<bool>(setupBarrierAdvance(storage, barrier, 1))
|
AsyncTask<bool>(setupBarrierAdvance(storage, barrier, 1))
|
||||||
};
|
};
|
||||||
const Log log3 {
|
const Log log3 {
|
||||||
{2, Handler::GroupSetup},
|
{2, Handler::GroupSetup},
|
||||||
@@ -1289,7 +1289,7 @@ void tst_TaskTree::testTree_data()
|
|||||||
Storage(storage),
|
Storage(storage),
|
||||||
Storage(barrier),
|
Storage(barrier),
|
||||||
parallel,
|
parallel,
|
||||||
Async<bool>(setupBarrierAdvance(storage, barrier, 1)),
|
AsyncTask<bool>(setupBarrierAdvance(storage, barrier, 1)),
|
||||||
Group {
|
Group {
|
||||||
OnGroupSetup(groupSetup(2)),
|
OnGroupSetup(groupSetup(2)),
|
||||||
WaitForBarrier(barrier),
|
WaitForBarrier(barrier),
|
||||||
@@ -1319,8 +1319,8 @@ void tst_TaskTree::testTree_data()
|
|||||||
Storage(barrier),
|
Storage(barrier),
|
||||||
Storage(barrier2),
|
Storage(barrier2),
|
||||||
parallel,
|
parallel,
|
||||||
Async<bool>(setupBarrierAdvance(storage, barrier, 0)),
|
AsyncTask<bool>(setupBarrierAdvance(storage, barrier, 0)),
|
||||||
Async<bool>(setupBarrierAdvance(storage, barrier2, 0)),
|
AsyncTask<bool>(setupBarrierAdvance(storage, barrier2, 0)),
|
||||||
Group {
|
Group {
|
||||||
Group {
|
Group {
|
||||||
parallel,
|
parallel,
|
||||||
@@ -1363,8 +1363,8 @@ void tst_TaskTree::testTree_data()
|
|||||||
Storage(storage),
|
Storage(storage),
|
||||||
Storage(barrier),
|
Storage(barrier),
|
||||||
sequential,
|
sequential,
|
||||||
Async<bool>(setupBarrierAdvance(storage, barrier, 1)),
|
AsyncTask<bool>(setupBarrierAdvance(storage, barrier, 1)),
|
||||||
Async<bool>(setupBarrierAdvance(storage, barrier, 2)),
|
AsyncTask<bool>(setupBarrierAdvance(storage, barrier, 2)),
|
||||||
Group {
|
Group {
|
||||||
OnGroupSetup(groupSetup(2)),
|
OnGroupSetup(groupSetup(2)),
|
||||||
WaitForBarrier(barrier),
|
WaitForBarrier(barrier),
|
||||||
@@ -1389,8 +1389,8 @@ void tst_TaskTree::testTree_data()
|
|||||||
Storage(storage),
|
Storage(storage),
|
||||||
Storage(barrier),
|
Storage(barrier),
|
||||||
parallel,
|
parallel,
|
||||||
Async<bool>(setupBarrierAdvance(storage, barrier, 0)),
|
AsyncTask<bool>(setupBarrierAdvance(storage, barrier, 0)),
|
||||||
Async<bool>(setupBarrierAdvance(storage, barrier, 0)),
|
AsyncTask<bool>(setupBarrierAdvance(storage, barrier, 0)),
|
||||||
Group {
|
Group {
|
||||||
OnGroupSetup(groupSetup(2)),
|
OnGroupSetup(groupSetup(2)),
|
||||||
WaitForBarrier(barrier),
|
WaitForBarrier(barrier),
|
||||||
@@ -1428,8 +1428,8 @@ void tst_TaskTree::testTree_data()
|
|||||||
Test(setupTask(2)),
|
Test(setupTask(2)),
|
||||||
Test(setupTask(3))
|
Test(setupTask(3))
|
||||||
},
|
},
|
||||||
Async<bool>(setupBarrierAdvance(storage, barrier, 0)),
|
AsyncTask<bool>(setupBarrierAdvance(storage, barrier, 0)),
|
||||||
Async<bool>(setupBarrierAdvance(storage, barrier, 0))
|
AsyncTask<bool>(setupBarrierAdvance(storage, barrier, 0))
|
||||||
};
|
};
|
||||||
const Log log3 {
|
const Log log3 {
|
||||||
{2, Handler::GroupSetup},
|
{2, Handler::GroupSetup},
|
||||||
@@ -1448,8 +1448,8 @@ void tst_TaskTree::testTree_data()
|
|||||||
Storage(storage),
|
Storage(storage),
|
||||||
Storage(barrier),
|
Storage(barrier),
|
||||||
parallel,
|
parallel,
|
||||||
Async<bool>(setupBarrierAdvance(storage, barrier, 0)),
|
AsyncTask<bool>(setupBarrierAdvance(storage, barrier, 0)),
|
||||||
Async<bool>(setupBarrierAdvance(storage, barrier, 0)),
|
AsyncTask<bool>(setupBarrierAdvance(storage, barrier, 0)),
|
||||||
Group {
|
Group {
|
||||||
OnGroupSetup(groupSetup(2)),
|
OnGroupSetup(groupSetup(2)),
|
||||||
WaitForBarrier(barrier),
|
WaitForBarrier(barrier),
|
||||||
|
|||||||
@@ -153,19 +153,19 @@ int main(int argc, char *argv[])
|
|||||||
using namespace Tasking;
|
using namespace Tasking;
|
||||||
|
|
||||||
auto taskItem = [sync = &synchronizer, synchronizerCheckBox](TaskWidget *widget) {
|
auto taskItem = [sync = &synchronizer, synchronizerCheckBox](TaskWidget *widget) {
|
||||||
const auto setupHandler = [=](AsyncTask<void> &task) {
|
const auto setupHandler = [=](Async<void> &task) {
|
||||||
task.setConcurrentCallData(sleepInThread, widget->busyTime(), widget->isSuccess());
|
task.setConcurrentCallData(sleepInThread, widget->busyTime(), widget->isSuccess());
|
||||||
if (synchronizerCheckBox->isChecked())
|
if (synchronizerCheckBox->isChecked())
|
||||||
task.setFutureSynchronizer(sync);
|
task.setFutureSynchronizer(sync);
|
||||||
widget->setState(State::Running);
|
widget->setState(State::Running);
|
||||||
};
|
};
|
||||||
const auto doneHandler = [widget](const AsyncTask<void> &) {
|
const auto doneHandler = [widget](const Async<void> &) {
|
||||||
widget->setState(State::Done);
|
widget->setState(State::Done);
|
||||||
};
|
};
|
||||||
const auto errorHandler = [widget](const AsyncTask<void> &) {
|
const auto errorHandler = [widget](const Async<void> &) {
|
||||||
widget->setState(State::Error);
|
widget->setState(State::Error);
|
||||||
};
|
};
|
||||||
return Async<void>(setupHandler, doneHandler, errorHandler);
|
return AsyncTask<void>(setupHandler, doneHandler, errorHandler);
|
||||||
};
|
};
|
||||||
|
|
||||||
const Group root {
|
const Group root {
|
||||||
|
|||||||
Reference in New Issue
Block a user