|
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" |
@@ -2462,42 +2463,37 @@ LedgerManagerImpl::applySorobanStageClustersInParallel( |
2462 | 2463 | { |
2463 | 2464 | ZoneScoped; |
2464 | 2465 |
|
2465 | | - std::vector<std::unique_ptr<ThreadParallelApplyLedgerState>> threadStates; |
2466 | | - std::vector<std::future<std::unique_ptr<ThreadParallelApplyLedgerState>>> |
2467 | | - threadFutures; |
2468 | | - |
2469 | 2466 | DeactivateScopeGuard globalStateDeactivateGuard(globalState); |
2470 | 2467 |
|
| 2468 | + std::vector< |
| 2469 | + std::function<std::unique_ptr<ThreadParallelApplyLedgerState>()>> |
| 2470 | + tasks; |
| 2471 | + tasks.reserve(stage.numClusters()); |
2471 | 2472 | for (size_t i = 0; i < stage.numClusters(); ++i) |
2472 | 2473 | { |
2473 | | - auto const& cluster = stage.getCluster(i); |
2474 | | - auto threadStatePtr = std::make_unique<ThreadParallelApplyLedgerState>( |
2475 | | - app, globalState, cluster, i); |
2476 | | - threadFutures.emplace_back(std::async( |
2477 | | - std::launch::async, &LedgerManagerImpl::applyThread, this, |
2478 | | - std::ref(app), std::move(threadStatePtr), std::cref(cluster), |
2479 | | - std::cref(config), ledgerInfo, sorobanBasePrngSeed)); |
| 2474 | + tasks.emplace_back([this, &app, &globalState, &stage, i, &config, |
| 2475 | + &ledgerInfo, &sorobanBasePrngSeed]() { |
| 2476 | + auto const& cluster = stage.getCluster(i); |
| 2477 | + auto threadStatePtr = |
| 2478 | + std::make_unique<ThreadParallelApplyLedgerState>( |
| 2479 | + app, globalState, cluster, i); |
| 2480 | + return applyThread(app, std::move(threadStatePtr), cluster, config, |
| 2481 | + ledgerInfo, sorobanBasePrngSeed); |
| 2482 | + }); |
2480 | 2483 | } |
2481 | 2484 |
|
2482 | | - for (auto& threadFuture : threadFutures) |
| 2485 | + try |
2483 | 2486 | { |
2484 | | - releaseAssert(threadFuture.valid()); |
2485 | | - try |
2486 | | - { |
2487 | | - auto futureResult = threadFuture.get(); |
2488 | | - threadStates.emplace_back(std::move(futureResult)); |
2489 | | - } |
2490 | | - catch (std::exception const& e) |
2491 | | - { |
2492 | | - printErrorAndAbort("Exception on apply thread: ", e.what()); |
2493 | | - } |
2494 | | - catch (...) |
2495 | | - { |
2496 | | - printErrorAndAbort("Unknown exception on apply thread"); |
2497 | | - } |
| 2487 | + return app.getBatchExecutor().executeBatch(std::move(tasks)); |
| 2488 | + } |
| 2489 | + catch (std::exception const& e) |
| 2490 | + { |
| 2491 | + printErrorAndAbort("Exception on apply thread: ", e.what()); |
| 2492 | + } |
| 2493 | + catch (...) |
| 2494 | + { |
| 2495 | + printErrorAndAbort("Unknown exception on apply thread"); |
2498 | 2496 | } |
2499 | | - threadFutures.clear(); |
2500 | | - return threadStates; |
2501 | 2497 | } |
2502 | 2498 |
|
2503 | 2499 | void |
|
0 commit comments