From: Joel Rosdahl Date: Thu, 30 Oct 2025 17:43:23 +0000 (+0100) Subject: enhance: Make ProgressBar thread safe X-Git-Tag: v4.13~83 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2178fdf04b6111d8c1ab3e77d1ca9348d48d3324;p=thirdparty%2Fccache.git enhance: Make ProgressBar thread safe --- diff --git a/src/ccache/progressbar.cpp b/src/ccache/progressbar.cpp index b13e5b8b..fe513554 100644 --- a/src/ccache/progressbar.cpp +++ b/src/ccache/progressbar.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2019-2024 Joel Rosdahl and other contributors +// Copyright (C) 2019-2025 Joel Rosdahl and other contributors // // See doc/authors.adoc for a complete list of contributors. // @@ -76,6 +76,9 @@ ProgressBar::update(double value) DEBUG_ASSERT(value <= 1.0); int16_t new_value = static_cast(1000 * value); + + std::unique_lock lock(m_mutex); + if (new_value == m_current_value) { return; } diff --git a/src/ccache/progressbar.hpp b/src/ccache/progressbar.hpp index 7ea9d982..aaca112b 100644 --- a/src/ccache/progressbar.hpp +++ b/src/ccache/progressbar.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2019-2021 Joel Rosdahl and other contributors +// Copyright (C) 2019-2025 Joel Rosdahl and other contributors // // See doc/authors.adoc for a complete list of contributors. // @@ -20,6 +20,7 @@ #include #include +#include #include class ProgressBar @@ -34,6 +35,7 @@ public: void update(double value); private: + std::mutex m_mutex; const std::string m_header; const size_t m_width; const bool m_stdout_is_a_terminal; diff --git a/src/ccache/storage/local/localstorage.cpp b/src/ccache/storage/local/localstorage.cpp index d4b1bcda..c682c3ab 100644 --- a/src/ccache/storage/local/localstorage.cpp +++ b/src/ccache/storage/local/localstorage.cpp @@ -839,10 +839,10 @@ CompressionStatistics LocalStorage::get_compression_statistics( const uint32_t threads, const ProgressReceiver& progress_receiver) const { - std::atomic content_size{0}; - std::atomic actual_size{0}; - std::atomic incompressible_size{0}; - std::atomic completed_dirs{0}; + std::atomic content_size = 0; + std::atomic actual_size = 0; + std::atomic incompressible_size = 0; + std::atomic completed_dirs = 0; const size_t read_ahead = std::max(static_cast(10), 2 * static_cast(threads));