diff options
| author | Stefan Boberg <[email protected]> | 2024-04-26 14:43:40 +0200 |
|---|---|---|
| committer | GitHub Enterprise <[email protected]> | 2024-04-26 14:43:40 +0200 |
| commit | eedb2cfbbe928b99a8283fea16f0d22b41cf80d0 (patch) | |
| tree | b0d50b7b7a07b347c246d6fee4a0ed311f13eb37 /src/zenutil/include | |
| parent | oplog iterate chunks content type (#65) (diff) | |
| download | zen-eedb2cfbbe928b99a8283fea16f0d22b41cf80d0.tar.xz zen-eedb2cfbbe928b99a8283fea16f0d22b41cf80d0.zip | |
miscellaneous minor bugfixes (#66)v5.5.0
this change addresses some TSAN warnings for improved robustness and less TSAN noise
- Added dedicated timer for EnqueueStateExitFlagTimer
- Made log formatter `fullformatter` output consistent time stamps across threads
- Made Linux/Mac event implementation TSAN clean
Diffstat (limited to 'src/zenutil/include')
| -rw-r--r-- | src/zenutil/include/zenutil/logging/fullformatter.h | 15 |
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 |