Use mutex to allow for concurrent update requests

This commit is contained in:
Dan Paulat 2023-04-22 23:28:30 -05:00
parent 08654bb7b0
commit 26ea4f4771

View file

@ -24,7 +24,7 @@ static const std::string kScwxReleaseEndpoint {
class UpdateManager::Impl class UpdateManager::Impl
{ {
public: public:
explicit Impl(UpdateManager* self) : self_ {self}, releases_ {} {} explicit Impl(UpdateManager* self) : self_ {self} {}
~Impl() {} ~Impl() {}
@ -38,9 +38,11 @@ public:
UpdateManager* self_; UpdateManager* self_;
std::vector<types::gh::Release> releases_; std::mutex updateMutex_ {};
types::gh::Release latestRelease_;
std::string latestVersion_; std::vector<types::gh::Release> releases_ {};
types::gh::Release latestRelease_ {};
std::string latestVersion_ {};
}; };
UpdateManager::UpdateManager() : p(std::make_unique<Impl>(this)) {} UpdateManager::UpdateManager() : p(std::make_unique<Impl>(this)) {}
@ -97,6 +99,8 @@ boost::json::value UpdateManager::Impl::ParseResponseText(const std::string& s)
bool UpdateManager::CheckForUpdates(const std::string& currentVersion) bool UpdateManager::CheckForUpdates(const std::string& currentVersion)
{ {
std::unique_lock lock(p->updateMutex_);
logger_->info("Checking for updates"); logger_->info("Checking for updates");
// Query GitHub for releases // Query GitHub for releases