diff options
author | Jarek Kobus <[email protected]> | 2025-06-30 08:37:13 +0200 |
---|---|---|
committer | Jarek Kobus <[email protected]> | 2025-07-01 10:08:47 +0000 |
commit | 587f6ce4d1e4d0f6da49ca5b21a4232470676897 (patch) | |
tree | 56f6b85ec6ba9db13da1560db50b242c89a7480e | |
parent | c7631c36d1cf0d912032adce4f11b9d598d25d7f (diff) |
Rename SharedBarrier into StartedBarrier and derive it
directly from Barrier. The only difference to Barrier
is that the default c'tor starts the barrier automatically.
Rename MultiBarrier into StoredMultiBarrier
and SingleBarrier into StoredBarrier, so that it's clear
we are operating on Storage<>.
Change-Id: Ia913d254d363aebd0783db2a532b95c5f4046170
Reviewed-by: hjk <[email protected]>
-rw-r--r-- | src/libs/solutions/tasking/barrier.h | 42 | ||||
-rw-r--r-- | src/libs/solutions/tasking/tasktree.cpp | 2 | ||||
-rw-r--r-- | src/plugins/android/androiddebugsupport.cpp | 2 | ||||
-rw-r--r-- | src/plugins/android/androidrunner.cpp | 6 | ||||
-rw-r--r-- | src/plugins/android/androidrunner.h | 2 | ||||
-rw-r--r-- | src/plugins/android/androidrunnerworker.cpp | 14 | ||||
-rw-r--r-- | src/plugins/debugger/debuggerruncontrol.cpp | 8 | ||||
-rw-r--r-- | src/plugins/ios/iosrunner.cpp | 22 | ||||
-rw-r--r-- | src/plugins/valgrind/valgrindprocess.cpp | 4 | ||||
-rw-r--r-- | tests/auto/solutions/tasking/tst_tasking.cpp | 20 |
10 files changed, 57 insertions, 65 deletions
diff --git a/src/libs/solutions/tasking/barrier.h b/src/libs/solutions/tasking/barrier.h index 3e27a4bd827..cfe6acffd80 100644 --- a/src/libs/solutions/tasking/barrier.h +++ b/src/libs/solutions/tasking/barrier.h @@ -13,7 +13,7 @@ QT_BEGIN_NAMESPACE namespace Tasking { -class TASKING_EXPORT Barrier final : public QObject +class TASKING_EXPORT Barrier : public QObject { Q_OBJECT @@ -41,33 +41,26 @@ private: using BarrierTask = SimpleCustomTask<Barrier>; template <int Limit = 1> -class SharedBarrier +class StartedBarrier final : public Barrier { public: - static_assert(Limit > 0, "SharedBarrier's limit should be 1 or more."); - SharedBarrier() : m_barrier(new Barrier) { - m_barrier->setLimit(Limit); - m_barrier->start(); + static_assert(Limit > 0, "StartedBarrier's limit should be 1 or more."); + StartedBarrier() + { + setLimit(Limit); + start(); } - Barrier *barrier() const { return m_barrier.get(); } - -private: - std::shared_ptr<Barrier> m_barrier; }; template <int Limit = 1> -using MultiBarrier = Storage<SharedBarrier<Limit>>; - -// Can't write: "MultiBarrier barrier;". Only "MultiBarrier<> barrier;" would work. -// Can't have one alias with default type in C++17, getting the following error: -// alias template deduction only available with C++20. -using SingleBarrier = MultiBarrier<1>; +using StoredMultiBarrier = Storage<StartedBarrier<Limit>>; +using StoredBarrier = StoredMultiBarrier<1>; template <int Limit> -ExecutableItem waitForBarrierTask(const MultiBarrier<Limit> &sharedBarrier) +ExecutableItem waitForBarrierTask(const StoredMultiBarrier<Limit> &storedBarrier) { - return BarrierTask([sharedBarrier](Barrier &barrier) { - SharedBarrier<Limit> *activeBarrier = sharedBarrier.activeStorage(); + return BarrierTask([storedBarrier](Barrier &barrier) { + Barrier *activeBarrier = storedBarrier.activeStorage(); if (!activeBarrier) { qWarning("The barrier referenced from WaitForBarrier element " "is not reachable in the running tree. " @@ -76,13 +69,12 @@ ExecutableItem waitForBarrierTask(const MultiBarrier<Limit> &sharedBarrier) "The WaitForBarrier task finishes with an error. "); return SetupResult::StopWithError; } - Barrier *activeSharedBarrier = activeBarrier->barrier(); - const std::optional<DoneResult> result = activeSharedBarrier->result(); + const std::optional<DoneResult> result = activeBarrier->result(); if (result.has_value()) { return *result == DoneResult::Success ? SetupResult::StopWithSuccess : SetupResult::StopWithError; } - QObject::connect(activeSharedBarrier, &Barrier::done, &barrier, &Barrier::stopWithResult); + QObject::connect(activeBarrier, &Barrier::done, &barrier, &Barrier::stopWithResult); return SetupResult::Continue; }); } @@ -95,7 +87,7 @@ ExecutableItem signalAwaiter(const typename QtPrivate::FunctionPointer<Signal>:: }); } -using BarrierKickerGetter = std::function<ExecutableItem(const SingleBarrier &)>; +using BarrierKickerGetter = std::function<ExecutableItem(const StoredBarrier &)>; class TASKING_EXPORT When final { @@ -111,13 +103,13 @@ public: WorkflowPolicy policy = WorkflowPolicy::StopOnError) : m_workflowPolicy(policy) { - m_barrierKicker = [taskHandler = customTask.m_taskHandler, signal](const SingleBarrier &barrier) { + m_barrierKicker = [taskHandler = customTask.m_taskHandler, signal](const StoredBarrier &barrier) { auto handler = std::move(taskHandler); const auto wrappedSetupHandler = [originalSetupHandler = std::move(handler.m_setupHandler), barrier, signal](TaskInterface &taskInterface) { const SetupResult setupResult = std::invoke(originalSetupHandler, taskInterface); Adapter &adapter = static_cast<Adapter &>(taskInterface); - QObject::connect(adapter.task(), signal, barrier->barrier(), &Barrier::advance); + QObject::connect(adapter.task(), signal, barrier.activeStorage(), &Barrier::advance); return setupResult; }; handler.m_setupHandler = std::move(wrappedSetupHandler); diff --git a/src/libs/solutions/tasking/tasktree.cpp b/src/libs/solutions/tasking/tasktree.cpp index 2cfe08020db..b723533ba7a 100644 --- a/src/libs/solutions/tasking/tasktree.cpp +++ b/src/libs/solutions/tasking/tasktree.cpp @@ -1298,7 +1298,7 @@ Group operator>>(const For &forItem, const Do &doItem) Group operator>>(const When &whenItem, const Do &doItem) { - const SingleBarrier barrier; + const StoredBarrier barrier; return { barrier, diff --git a/src/plugins/android/androiddebugsupport.cpp b/src/plugins/android/androiddebugsupport.cpp index 9da4d1d9f70..cbe3de5e457 100644 --- a/src/plugins/android/androiddebugsupport.cpp +++ b/src/plugins/android/androiddebugsupport.cpp @@ -171,7 +171,7 @@ public: { setId("AndroidDebugWorkerFactory"); setRecipeProducer([](RunControl *runControl) { - const auto kicker = [runControl](const SingleBarrier &barrier) { + const auto kicker = [runControl](const StoredBarrier &barrier) { return androidKicker(barrier, runControl); }; return When (kicker) >> Do { diff --git a/src/plugins/android/androidrunner.cpp b/src/plugins/android/androidrunner.cpp index dd36bd38f5d..4e82836754d 100644 --- a/src/plugins/android/androidrunner.cpp +++ b/src/plugins/android/androidrunner.cpp @@ -37,7 +37,7 @@ using namespace Utils; namespace Android::Internal { -Group androidKicker(const SingleBarrier &barrier, RunControl *runControl) +Group androidKicker(const StoredBarrier &barrier, RunControl *runControl) { BuildConfiguration *bc = runControl->buildConfiguration(); QTC_ASSERT(bc, return {}); @@ -108,7 +108,7 @@ Group androidKicker(const SingleBarrier &barrier, RunControl *runControl) auto iface = runStorage().activeStorage(); QObject::connect(iface, &RunInterface::canceled, glue, &RunnerInterface::cancel); - QObject::connect(glue, &RunnerInterface::started, barrier->barrier(), &Barrier::advance, + QObject::connect(glue, &RunnerInterface::started, barrier.activeStorage(), &Barrier::advance, Qt::QueuedConnection); QObject::connect(glue, &RunnerInterface::finished, runControl, [runControl](const QString &errorString) { runControl->postMessage(errorString, Utils::NormalMessageFormat); @@ -127,7 +127,7 @@ Group androidKicker(const SingleBarrier &barrier, RunControl *runControl) Group androidRecipe(RunControl *runControl) { - const auto kicker = [runControl](const SingleBarrier &barrier) { + const auto kicker = [runControl](const StoredBarrier &barrier) { return androidKicker(barrier, runControl); }; return When (kicker) >> Do { diff --git a/src/plugins/android/androidrunner.h b/src/plugins/android/androidrunner.h index 00c0bebb075..31c0d1ebb5b 100644 --- a/src/plugins/android/androidrunner.h +++ b/src/plugins/android/androidrunner.h @@ -10,7 +10,7 @@ namespace Android::Internal { -Tasking::Group androidKicker(const Tasking::SingleBarrier &barrier, +Tasking::Group androidKicker(const Tasking::StoredBarrier &barrier, ProjectExplorer::RunControl *runControl); Tasking::Group androidRecipe(ProjectExplorer::RunControl *runControl); void setupAndroidRunWorker(); diff --git a/src/plugins/android/androidrunnerworker.cpp b/src/plugins/android/androidrunnerworker.cpp index cd9631bbdc0..eeb82f8288d 100644 --- a/src/plugins/android/androidrunnerworker.cpp +++ b/src/plugins/android/androidrunnerworker.cpp @@ -301,8 +301,8 @@ static ExecutableItem removeForwardPortRecipe(RunnerStorage *storage, const QStr // The startBarrier is passed when logcat process received "Sending WAIT chunk" message. // The settledBarrier is passed when logcat process received "debugger has settled" message. static ExecutableItem jdbRecipe(const Storage<RunnerStorage> &storage, - const SingleBarrier &startBarrier, - const SingleBarrier &settledBarrier) + const StoredBarrier &startBarrier, + const StoredBarrier &settledBarrier) { const auto onSetup = [storage] { return storage->m_useCppDebugger ? SetupResult::Continue : SetupResult::StopWithSuccess; @@ -324,7 +324,7 @@ static ExecutableItem jdbRecipe(const Storage<RunnerStorage> &storage, process.setProcessMode(ProcessMode::Writer); process.setProcessChannelMode(QProcess::MergedChannels); process.setReaperTimeout(s_jdbTimeout); - QObject::connect(settledBarrier->barrier(), &Barrier::done, &process, [processPtr = &process] { + QObject::connect(settledBarrier.activeStorage(), &Barrier::done, &process, [processPtr = &process] { processPtr->write("ignore uncaught java.lang.Throwable\n" "threads\n" "cont\n" @@ -354,8 +354,8 @@ static ExecutableItem logcatRecipe(const Storage<RunnerStorage> &storage) }; const Storage<Buffer> bufferStorage; - const SingleBarrier startJdbBarrier; // When logcat received "Sending WAIT chunk". - const SingleBarrier settledJdbBarrier; // When logcat received "debugger has settled". + const StoredBarrier startJdbBarrier; // When logcat received "Sending WAIT chunk". + const StoredBarrier settledJdbBarrier; // When logcat received "debugger has settled". const auto onTimeSetup = [storage](Process &process) { process.setCommand(storage->adbCommand({"shell", "date", "+%s"})); @@ -368,8 +368,8 @@ static ExecutableItem logcatRecipe(const Storage<RunnerStorage> &storage) const auto onLogcatSetup = [storage, bufferStorage, startJdbBarrier, settledJdbBarrier](Process &process) { RunnerStorage *storagePtr = storage.activeStorage(); Buffer *bufferPtr = bufferStorage.activeStorage(); - const auto parseLogcat = [storagePtr, bufferPtr, start = startJdbBarrier->barrier(), - settled = settledJdbBarrier->barrier(), processPtr = &process]( + const auto parseLogcat = [storagePtr, bufferPtr, start = startJdbBarrier.activeStorage(), + settled = settledJdbBarrier.activeStorage(), processPtr = &process]( QProcess::ProcessChannel channel) { if (storagePtr->m_processPID == -1) return; diff --git a/src/plugins/debugger/debuggerruncontrol.cpp b/src/plugins/debugger/debuggerruncontrol.cpp index 10083524581..5e872232780 100644 --- a/src/plugins/debugger/debuggerruncontrol.cpp +++ b/src/plugins/debugger/debuggerruncontrol.cpp @@ -166,7 +166,7 @@ ExecutableItem coreFileRecipe(const Storage<DebuggerData> &storage) }; } -ExecutableItem terminalRecipe(const Storage<DebuggerData> &storage, const SingleBarrier &barrier) +ExecutableItem terminalRecipe(const Storage<DebuggerData> &storage, const StoredBarrier &barrier) { const auto onSetup = [storage, barrier] { DebuggerRunParameters &runParameters = storage->runParameters; @@ -177,7 +177,7 @@ ExecutableItem terminalRecipe(const Storage<DebuggerData> &storage, const Single if (useCdbConsole) runParameters.setUseTerminal(false); if (!runParameters.useTerminal()) { - barrier->barrier()->advance(); + barrier->advance(); return; } @@ -192,7 +192,7 @@ ExecutableItem terminalRecipe(const Storage<DebuggerData> &storage, const Single process->setRunData(stub); QObject::connect(process, &Process::started, process, - [runParameters = &runParameters, process, barrier = barrier->barrier()] { + [runParameters = &runParameters, process, barrier = barrier.activeStorage()] { runParameters->setApplicationPid(process->processId()); runParameters->setApplicationMainThreadId(process->applicationMainThreadId()); barrier->advance(); @@ -704,7 +704,7 @@ Group debuggerRecipe(RunControl *runControl, const DebuggerRunParameters &initia parametersModifier(storage->runParameters); }; - const auto terminalKicker = [storage](const SingleBarrier &barrier) { + const auto terminalKicker = [storage](const StoredBarrier &barrier) { return terminalRecipe(storage, barrier); }; diff --git a/src/plugins/ios/iosrunner.cpp b/src/plugins/ios/iosrunner.cpp index cba6b95a9d6..c03da3e6c49 100644 --- a/src/plugins/ios/iosrunner.cpp +++ b/src/plugins/ios/iosrunner.cpp @@ -219,11 +219,11 @@ static GroupItem killProcess(const Storage<AppInfo> &appInfo) return ProcessTask(onSetup, DoneResult::Success); // we tried our best and don't care at this point } -static Group deviceCtlKicker(const SingleBarrier &barrier, RunControl *runControl, +static Group deviceCtlKicker(const StoredBarrier &barrier, RunControl *runControl, const Storage<AppInfo> &appInfo, const Storage<TemporaryFile> tempFileStorage, bool startStopped) { - const auto launchApp = [runControl, appInfo, tempFileStorage, startStopped](const SingleBarrier &barrier) { + const auto launchApp = [runControl, appInfo, tempFileStorage, startStopped](const StoredBarrier &barrier) { const auto onSetup = [runControl, appInfo, tempFileStorage, startStopped, barrier](Process &process) { const QStringList startStoppedArg = startStopped ? QStringList("--start-stopped") : QStringList(); @@ -241,7 +241,7 @@ static Group deviceCtlKicker(const SingleBarrier &barrier, RunControl *runContro + QStringList({"--console", appInfo->bundleIdentifier}) + appInfo->arguments; process.setCommand({FilePath::fromString("/usr/bin/xcrun"), args}); - QObject::connect(&process, &Process::started, barrier->barrier(), &Barrier::advance); + QObject::connect(&process, &Process::started, barrier.activeStorage(), &Barrier::advance); QObject::connect(&process, &Process::readyReadStandardError, runControl, [runControl, process = &process] { @@ -270,7 +270,7 @@ static Group deviceCtlKicker(const SingleBarrier &barrier, RunControl *runContro const auto onDone = [runControl, appInfo, barrier](DoneWith result) { if (result == DoneWith::Success) { runControl->setAttachPid(ProcessHandle(appInfo->processIdentifier)); - barrier->barrier()->advance(); + barrier->advance(); } else { runControl->postMessage(Tr::tr("Failed to retrieve process ID."), ErrorMessageFormat); } @@ -303,7 +303,7 @@ static Group killApp(RunControl *runControl, const Storage<AppInfo> &appInfo) }; } -static Group deviceCtlKicker(const SingleBarrier &barrier, RunControl *runControl, bool startStopped) +static Group deviceCtlKicker(const StoredBarrier &barrier, RunControl *runControl, bool startStopped) { const Storage<AppInfo> appInfo; const Storage<TemporaryFile> tempFileStorage{QString("devicectl")}; @@ -336,7 +336,7 @@ static Group deviceCtlKicker(const SingleBarrier &barrier, RunControl *runContro static Group deviceCtlRecipe(RunControl *runControl, bool startStopped) { - const auto kicker = [runControl, startStopped](const SingleBarrier &barrier) { + const auto kicker = [runControl, startStopped](const StoredBarrier &barrier) { return deviceCtlKicker(barrier, runControl, startStopped); }; return When (kicker) >> Do { @@ -579,7 +579,7 @@ static void handleIosToolStartedOnSimulator( barrier->advance(); } -static Group iosToolKicker(const SingleBarrier &barrier, RunControl *runControl, const DebugInfo &debugInfo) +static Group iosToolKicker(const StoredBarrier &barrier, RunControl *runControl, const DebugInfo &debugInfo) { stopRunningRunControl(runControl); const IosDeviceTypeAspect::Data *data = runControl->aspectData<IosDeviceTypeAspect>(); @@ -603,7 +603,7 @@ static Group iosToolKicker(const SingleBarrier &barrier, RunControl *runControl, runner.setDeviceType(deviceType); RunInterface *iface = runStorage().activeStorage(); runner.setStartHandler([runControl, debugInfo, bundleDir, device, iface, - barrier = barrier->barrier()](IosToolHandler *handler) { + barrier = barrier.activeStorage()](IosToolHandler *handler) { const auto messageHandler = [runControl](const QString &message) { runControl->postMessage(message, StdOutFormat); }; @@ -667,7 +667,7 @@ static Group iosToolKicker(const SingleBarrier &barrier, RunControl *runControl, static Group iosToolRecipe(RunControl *runControl, const DebugInfo &debugInfo = {}) { - const auto kicker = [runControl, debugInfo](const SingleBarrier &barrier) { + const auto kicker = [runControl, debugInfo](const StoredBarrier &barrier) { return iosToolKicker(barrier, runControl, debugInfo); }; return When (kicker) >> Do { @@ -812,7 +812,7 @@ static Group debugRecipe(RunControl *runControl) if (isIosRunner) { const DebugInfo debugInfo{rp.isQmlDebugging() ? QmlDebuggerServices : NoQmlDebugServices, rp.isCppDebugging()}; - kicker = [runControl, debugInfo](const SingleBarrier &barrier) { + kicker = [runControl, debugInfo](const StoredBarrier &barrier) { return iosToolKicker(barrier, runControl, debugInfo); }; } else { @@ -820,7 +820,7 @@ static Group debugRecipe(RunControl *runControl) rp.setInferiorExecutable(data->localExecutable); const bool warnAboutQml = rp.isQmlDebugging(); rp.setQmlDebugging(false); - kicker = [runControl, warnAboutDebug = rp.isCppDebugging(), warnAboutQml](const SingleBarrier &barrier) { + kicker = [runControl, warnAboutDebug = rp.isCppDebugging(), warnAboutQml](const StoredBarrier &barrier) { const auto onSetup = [runControl, warnAboutDebug, warnAboutQml] { QTC_ASSERT(warnAboutDebug, runControl->postMessage(msgOnlyCppDebuggingSupported(), ErrorMessageFormat); diff --git a/src/plugins/valgrind/valgrindprocess.cpp b/src/plugins/valgrind/valgrindprocess.cpp index ce59aa1e632..dac37b92c5d 100644 --- a/src/plugins/valgrind/valgrindprocess.cpp +++ b/src/plugins/valgrind/valgrindprocess.cpp @@ -100,13 +100,13 @@ Group ValgrindProcessPrivate::runRecipe() const }; Storage<ValgrindStorage> storage; - SingleBarrier xmlBarrier; + StoredBarrier xmlBarrier; const auto isSetupValid = [this, storage, xmlBarrier] { ValgrindStorage *storagePtr = storage.activeStorage(); storagePtr->m_valgrindCommand.setExecutable(m_valgrindCommand.executable()); if (!m_localServerAddress.isNull()) { - Barrier *barrier = xmlBarrier->barrier(); + Barrier *barrier = xmlBarrier.activeStorage(); const QString ip = m_localServerAddress.toString(); QTcpServer *xmlServer = new QTcpServer; diff --git a/tests/auto/solutions/tasking/tst_tasking.cpp b/tests/auto/solutions/tasking/tst_tasking.cpp index 2d6851ac333..d7af496b8e0 100644 --- a/tests/auto/solutions/tasking/tst_tasking.cpp +++ b/tests/auto/solutions/tasking/tst_tasking.cpp @@ -381,20 +381,20 @@ private: using TickAndDoneTask = SimpleCustomTask<TickAndDone>; -template <typename SharedBarrierType> +template <typename StoredBarrierType> ExecutableItem createBarrierAdvance(const Storage<CustomStorage> &storage, - const SharedBarrierType &barrier, int taskId) + const StoredBarrierType &barrier, int taskId) { return TickAndDoneTask([storage, barrier, taskId](TickAndDone &tickAndDone) { tickAndDone.setInterval(1ms); storage->m_log.append({taskId, Handler::Setup}); CustomStorage *currentStorage = storage.activeStorage(); - Barrier *sharedBarrier = barrier->barrier(); - QObject::connect(&tickAndDone, &TickAndDone::tick, sharedBarrier, - [currentStorage, sharedBarrier, taskId] { + Barrier *activeBarrier = barrier.activeStorage(); + QObject::connect(&tickAndDone, &TickAndDone::tick, activeBarrier, + [currentStorage, activeBarrier, taskId] { currentStorage->m_log.append({taskId, Handler::BarrierAdvance}); - sharedBarrier->advance(); + activeBarrier->advance(); }); }); } @@ -2277,7 +2277,7 @@ void tst_Tasking::testTree_data() } { - SingleBarrier barrier; + StoredBarrier barrier; // Test that barrier advance, triggered from inside the task described by // createBarrierAdvance, placed BEFORE the group containing the waitFor() element @@ -2393,7 +2393,7 @@ void tst_Tasking::testTree_data() // Test two separate single barriers. - SingleBarrier barrier2; + StoredBarrier barrier2; const Group root5 { storage, @@ -2435,7 +2435,7 @@ void tst_Tasking::testTree_data() << TestData{storage, root5, log5, 5, DoneWith::Success, 5}; const auto barrierKicker = [storage](int taskId) { - return [storage, taskId](const SingleBarrier &barrier) { + return [storage, taskId](const StoredBarrier &barrier) { return createBarrierAdvance(storage, barrier, taskId); }; }; @@ -2502,7 +2502,7 @@ void tst_Tasking::testTree_data() } { - MultiBarrier<2> barrier; + StoredMultiBarrier<2> barrier; // Test that multi barrier advance, triggered from inside the tasks described by // createBarrierAdvance, placed BEFORE the group containing the waitFor() element |