Stop using a mutex for guarding CachedCalendar.

This commit is contained in:
Skirmantas Kligys 2020-02-03 16:19:32 -08:00
parent 218bb3bc2b
commit 4c40f9c635

View File

@ -1,5 +1,4 @@
#include "modules/clock.hpp"
#include <mutex>
#include <sstream>
using zoned_time = date::zoned_time<std::chrono::system_clock::duration>;
@ -37,14 +36,11 @@ struct CachedCalendar {
}
};
std::mutex cached_calendar_mutex; // protects cached_calendar.
CachedCalendar cached_calendar;
std::string calendar_text(const waybar_time& wtime, const date::weekday& first_dow) {
const auto daypoint = date::floor<date::days>(wtime.ztime.get_local_time());
const auto ymd = date::year_month_day(daypoint);
const std::lock_guard<std::mutex> lock(cached_calendar_mutex);
if (cached_calendar.ymd == ymd) {
return cached_calendar.text;
}