mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
Stop using a mutex for guarding CachedCalendar.
This commit is contained in:
parent
218bb3bc2b
commit
4c40f9c635
@ -1,5 +1,4 @@
|
|||||||
#include "modules/clock.hpp"
|
#include "modules/clock.hpp"
|
||||||
#include <mutex>
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
using zoned_time = date::zoned_time<std::chrono::system_clock::duration>;
|
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;
|
CachedCalendar cached_calendar;
|
||||||
|
|
||||||
std::string calendar_text(const waybar_time& wtime, const date::weekday& first_dow) {
|
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 daypoint = date::floor<date::days>(wtime.ztime.get_local_time());
|
||||||
const auto ymd = date::year_month_day(daypoint);
|
const auto ymd = date::year_month_day(daypoint);
|
||||||
|
|
||||||
const std::lock_guard<std::mutex> lock(cached_calendar_mutex);
|
|
||||||
if (cached_calendar.ymd == ymd) {
|
if (cached_calendar.ymd == ymd) {
|
||||||
return cached_calendar.text;
|
return cached_calendar.text;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user