Skip to content
This repository has been archived by the owner on Aug 22, 2023. It is now read-only.

Commit

Permalink
setting --resource-backend.updatePeriod to value <= 0 disables automa…
Browse files Browse the repository at this point in the history
…tic resource update
  • Loading branch information
vaclavblazek committed Jul 26, 2017
1 parent 13e072d commit 9e31478
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions mapproxy/src/mapproxy/generator/generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,9 +462,11 @@ void Generators::Detail::updater()
{
dbglog::thread_id("updater");

// invalidate any update request
updateRequest_ = false;

while (running_) {
// default sleep time in seconds
std::chrono::seconds sleep(config_.resourceUpdatePeriod);

try {
Expand All @@ -473,18 +475,30 @@ void Generators::Detail::updater()
// pass
} catch (const std::exception &e) {
LOG(err2) << "Resource info update failed: <" << e.what() << ">.";
sleep = std::chrono::seconds(5);
if (config_.resourceUpdatePeriod > 0) {
sleep = std::chrono::seconds(5);
}
}

// sleep for 5 minutes
// sleep for configured time minutes
{
std::unique_lock<std::mutex> lock(updaterLock_);
updaterCond_.wait_for(lock, sleep, [this]() -> bool

// condition variable wait predicate
const auto predicate([this]() -> bool
{
auto updateRequest
(std::atomic_exchange(&updateRequest_, false));
return !running_ || updateRequest;
});

if (config_.resourceUpdatePeriod > 0) {
// wait for given duration
updaterCond_.wait_for(lock, sleep, predicate);
} else {
// wait untill bugged
updaterCond_.wait(lock, predicate);
}
}
}
}
Expand Down

0 comments on commit 9e31478

Please sign in to comment.