Module: check_mk
Branch: master
Commit: 55fa66b01e551e338a7b10eb0078d7e292362d2d
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=55fa66b01e551e…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Thu Aug 17 09:00:01 2017 +0200
Improved naming and added a comment.
Change-Id: I44e7bb7db00f38eb4e16af7a660232dd1e4b7033
---
livestatus/src/TimeperiodsCache.cc | 6 +++---
livestatus/src/TimeperiodsCache.h | 4 +++-
2 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/livestatus/src/TimeperiodsCache.cc b/livestatus/src/TimeperiodsCache.cc
index cc894ec..3921431 100644
--- a/livestatus/src/TimeperiodsCache.cc
+++ b/livestatus/src/TimeperiodsCache.cc
@@ -41,7 +41,7 @@ TimeperiodsCache::TimeperiodsCache(Logger *logger)
TimeperiodsCache::~TimeperiodsCache() = default;
void TimeperiodsCache::logCurrentTimeperiods() {
- lock_guard<mutex> lg(_cache_lock);
+ lock_guard<mutex> lg(_mutex);
time_t now = time(nullptr);
// Loop over all timeperiods and compute if we are
// currently in. Detect the case where no time periods
@@ -61,7 +61,7 @@ void TimeperiodsCache::logCurrentTimeperiods() {
}
void TimeperiodsCache::update(time_t now) {
- lock_guard<mutex> lg(_cache_lock);
+ lock_guard<mutex> lg(_mutex);
// update cache only once a minute. The timeperiod
// definitions have 1 minute as granularity, so a
@@ -110,7 +110,7 @@ bool TimeperiodsCache::inTimeperiod(const char *tpname) const {
}
bool TimeperiodsCache::inTimeperiod(timeperiod *tp) const {
- lock_guard<mutex> lg(_cache_lock);
+ lock_guard<mutex> lg(_mutex);
auto it = _cache.find(tp);
bool is_in;
if (it != _cache.end()) {
diff --git a/livestatus/src/TimeperiodsCache.h b/livestatus/src/TimeperiodsCache.h
index 6c4ac6a..01c7440 100644
--- a/livestatus/src/TimeperiodsCache.h
+++ b/livestatus/src/TimeperiodsCache.h
@@ -43,9 +43,11 @@ public:
private:
Logger *const _logger;
+
+ // The mutex protects _cache_time and _cache.
+ mutable std::mutex _mutex;
time_t _cache_time;
std::map<const timeperiod *, bool> _cache;
- mutable std::mutex _cache_lock;
void logTransition(char *name, int from, int to) const;
};