From 5f6ff55e97104e46c1b5c2c94b39ea0fca35ca7c Mon Sep 17 00:00:00 2001 From: Paul Cristian Sarbu Date: Thu, 7 Mar 2024 15:44:28 +0100 Subject: just: Replace singletons for progress tracking and statistics... ...with regular instances that have controlled life-times. This avoids race conditions in tracking and reporting the results of analysis and build, as the serve endpoint can orchestrate multiple builds at the same time asynchronously. As a bonus side-effect this also ensures the correctness of the progress reporting per orchestrated build. --- .../progress_reporting/progress_reporter.cpp | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'src/buildtool/progress_reporting/progress_reporter.cpp') diff --git a/src/buildtool/progress_reporting/progress_reporter.cpp b/src/buildtool/progress_reporting/progress_reporter.cpp index 86ec0c0e..27960172 100644 --- a/src/buildtool/progress_reporting/progress_reporter.cpp +++ b/src/buildtool/progress_reporting/progress_reporter.cpp @@ -17,25 +17,23 @@ #include #include "fmt/core.h" -#include "gsl/gsl" -#include "src/buildtool/common/statistics.hpp" #include "src/buildtool/logging/log_level.hpp" #include "src/buildtool/logging/logger.hpp" -#include "src/buildtool/progress_reporting/progress.hpp" -auto ProgressReporter::Reporter() noexcept -> progress_reporter_t { - return BaseProgressReporter::Reporter([]() { - int total = gsl::narrow(Progress::Instance().OriginMap().size()); +auto ProgressReporter::Reporter( + gsl::not_null const& stats, + gsl::not_null const& progress) noexcept -> progress_reporter_t { + return BaseProgressReporter::Reporter([stats, progress]() { + int total = gsl::narrow(progress->OriginMap().size()); // Note: order matters; queued has to be queried last - auto const& sample = Progress::Instance().TaskTracker().Sample(); - auto const& stats = Statistics::Instance(); - int cached = stats.ActionsCachedCounter(); - int run = stats.ActionsExecutedCounter(); - int queued = stats.ActionsQueuedCounter(); + auto const& sample = progress->TaskTracker().Sample(); + int cached = stats->ActionsCachedCounter(); + int run = stats->ActionsExecutedCounter(); + int queued = stats->ActionsQueuedCounter(); int active = queued - run - cached; std::string now_msg; if (active > 0 and !sample.empty()) { - auto const& origin_map = Progress::Instance().OriginMap(); + auto const& origin_map = progress->OriginMap(); auto origins = origin_map.find(sample); if (origins != origin_map.end() and !origins->second.empty()) { auto const& origin = origins->second[0]; -- cgit v1.2.3