Merge pull request #8142 from patricksjackson/atomic-sync

Replace unnecessary Sync<uint64_t> with std::atomic<uint64_t>
This commit is contained in:
John Ericson 2023-03-31 21:49:20 -04:00 committed by GitHub
commit 8ae9d66940
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -10,7 +10,6 @@
#include "archive.hh" #include "archive.hh"
#include "callback.hh" #include "callback.hh"
#include "remote-store.hh" #include "remote-store.hh"
#include "sync.hh"
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include <regex> #include <regex>
@ -1103,7 +1102,7 @@ std::map<StorePath, StorePath> copyPaths(
}; };
// total is accessed by each copy, which are each handled in separate threads // total is accessed by each copy, which are each handled in separate threads
Sync<uint64_t> _total = 0; std::atomic<uint64_t> total = 0;
for (auto & missingPath : sortedMissing) { for (auto & missingPath : sortedMissing) {
auto info = srcStore.queryPathInfo(missingPath); auto info = srcStore.queryPathInfo(missingPath);
@ -1126,9 +1125,8 @@ std::map<StorePath, StorePath> copyPaths(
PushActivity pact(act.id); PushActivity pact(act.id);
LambdaSink progressSink([&](std::string_view data) { LambdaSink progressSink([&](std::string_view data) {
auto total(_total.lock()); total += data.size();
*total += data.size(); act.progress(total, info->narSize);
act.progress(*total, info->narSize);
}); });
TeeSink tee { sink, progressSink }; TeeSink tee { sink, progressSink };