|
40 | 40 | #include "transactions/TransactionFrameBase.h" |
41 | 41 | #include "transactions/TransactionMeta.h" |
42 | 42 | #include "transactions/TransactionUtils.h" |
| 43 | +#include "util/BatchExecutor.h" |
43 | 44 | #include "util/DebugMetaUtils.h" |
44 | 45 | #include "util/Decoder.h" |
45 | 46 | #include "util/Fs.h" |
@@ -2639,42 +2640,37 @@ LedgerManagerImpl::applySorobanStageClustersInParallel( |
2639 | 2640 | { |
2640 | 2641 | ZoneScoped; |
2641 | 2642 |
|
2642 | | - std::vector<std::unique_ptr<ThreadParallelApplyLedgerState>> threadStates; |
2643 | | - std::vector<std::future<std::unique_ptr<ThreadParallelApplyLedgerState>>> |
2644 | | - threadFutures; |
2645 | | - |
2646 | 2643 | DeactivateScopeGuard globalStateDeactivateGuard(globalState); |
2647 | 2644 |
|
| 2645 | + std::vector< |
| 2646 | + std::function<std::unique_ptr<ThreadParallelApplyLedgerState>()>> |
| 2647 | + tasks; |
| 2648 | + tasks.reserve(stage.numClusters()); |
2648 | 2649 | for (size_t i = 0; i < stage.numClusters(); ++i) |
2649 | 2650 | { |
2650 | | - auto const& cluster = stage.getCluster(i); |
2651 | | - auto threadStatePtr = std::make_unique<ThreadParallelApplyLedgerState>( |
2652 | | - app, globalState, cluster, i); |
2653 | | - threadFutures.emplace_back(std::async( |
2654 | | - std::launch::async, &LedgerManagerImpl::applyThread, this, |
2655 | | - std::ref(app), std::move(threadStatePtr), std::cref(cluster), |
2656 | | - std::cref(config), ledgerInfo, sorobanBasePrngSeed)); |
| 2651 | + tasks.emplace_back([this, &app, &globalState, &stage, i, &config, |
| 2652 | + &ledgerInfo, &sorobanBasePrngSeed]() { |
| 2653 | + auto const& cluster = stage.getCluster(i); |
| 2654 | + auto threadStatePtr = |
| 2655 | + std::make_unique<ThreadParallelApplyLedgerState>( |
| 2656 | + app, globalState, cluster, i); |
| 2657 | + return applyThread(app, std::move(threadStatePtr), cluster, config, |
| 2658 | + ledgerInfo, sorobanBasePrngSeed); |
| 2659 | + }); |
2657 | 2660 | } |
2658 | 2661 |
|
2659 | | - for (auto& threadFuture : threadFutures) |
| 2662 | + try |
2660 | 2663 | { |
2661 | | - releaseAssert(threadFuture.valid()); |
2662 | | - try |
2663 | | - { |
2664 | | - auto futureResult = threadFuture.get(); |
2665 | | - threadStates.emplace_back(std::move(futureResult)); |
2666 | | - } |
2667 | | - catch (std::exception const& e) |
2668 | | - { |
2669 | | - printErrorAndAbort("Exception on apply thread: ", e.what()); |
2670 | | - } |
2671 | | - catch (...) |
2672 | | - { |
2673 | | - printErrorAndAbort("Unknown exception on apply thread"); |
2674 | | - } |
| 2664 | + return app.getBatchExecutor().executeBatch(std::move(tasks)); |
| 2665 | + } |
| 2666 | + catch (std::exception const& e) |
| 2667 | + { |
| 2668 | + printErrorAndAbort("Exception on apply thread: ", e.what()); |
| 2669 | + } |
| 2670 | + catch (...) |
| 2671 | + { |
| 2672 | + printErrorAndAbort("Unknown exception on apply thread"); |
2675 | 2673 | } |
2676 | | - threadFutures.clear(); |
2677 | | - return threadStates; |
2678 | 2674 | } |
2679 | 2675 |
|
2680 | 2676 | void |
|
0 commit comments