aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2024-04-26 11:48:15 +0000
committerDan Engelbrecht <[email protected]>2024-04-26 14:30:43 +0200
commit9e06517cffbb92f6e03e435dbba2e51402edd093 (patch)
tree3a3a28ca687ec783f6bcd4c150aa244714030a71 /src
parentadded dedicated timer for EnqueueStateExitFlagTimer (diff)
downloadzen-9e06517cffbb92f6e03e435dbba2e51402edd093.tar.xz
zen-9e06517cffbb92f6e03e435dbba2e51402edd093.zip
made fullformatter thread safe
Diffstat (limited to 'src')
-rw-r--r--src/zenutil/include/zenutil/logging/fullformatter.h15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/zenutil/include/zenutil/logging/fullformatter.h b/src/zenutil/include/zenutil/logging/fullformatter.h
index 146fea7a0..d4a04d3e5 100644
--- a/src/zenutil/include/zenutil/logging/fullformatter.h
+++ b/src/zenutil/include/zenutil/logging/fullformatter.h
@@ -42,6 +42,7 @@ public:
TimestampSeconds = std::chrono::duration_cast<std::chrono::seconds>(msg.time.time_since_epoch());
if (TimestampSeconds != m_LastLogSecs)
{
+ RwLock::ExclusiveLockScope _(m_TimestampLock);
m_LastLogSecs = TimestampSeconds;
m_CachedLocalTm = spdlog::details::os::localtime(spdlog::log_clock::to_time_t(msg.time));
@@ -66,10 +67,10 @@ public:
auto ElapsedTime = msg.time - m_Epoch;
TimestampSeconds = std::chrono::duration_cast<std::chrono::seconds>(ElapsedTime);
- // cache the date/time part for the next second.
-
- if (m_CacheTimestamp != TimestampSeconds || m_CachedDatetime.size() == 0)
+ if (m_CacheTimestamp.load() != TimestampSeconds)
{
+ RwLock::ExclusiveLockScope _(m_TimestampLock);
+
m_CacheTimestamp = TimestampSeconds;
int Count = int(TimestampSeconds.count());
@@ -90,7 +91,10 @@ public:
}
}
- OutBuffer.append(m_CachedDatetime.begin(), m_CachedDatetime.end());
+ {
+ RwLock::SharedLockScope _(m_TimestampLock);
+ OutBuffer.append(m_CachedDatetime.begin(), m_CachedDatetime.end());
+ }
auto millis = spdlog::details::fmt_helper::time_fraction<std::chrono::milliseconds>(msg.time);
spdlog::details::fmt_helper::pad3(static_cast<uint32_t>(millis.count()), OutBuffer);
@@ -180,11 +184,12 @@ private:
std::chrono::time_point<std::chrono::system_clock> m_Epoch;
std::tm m_CachedLocalTm;
std::chrono::seconds m_LastLogSecs;
- std::chrono::seconds m_CacheTimestamp{0};
+ std::atomic<std::chrono::seconds> m_CacheTimestamp;
spdlog::memory_buf_t m_CachedDatetime;
std::string m_LogId;
std::string m_LinePrefix;
bool m_UseFullDate = true;
+ RwLock m_TimestampLock;
};
} // namespace zen::logging