From 2473768fdb0aaa0dbb65606bf330f4e8154889de Mon Sep 17 00:00:00 2001 From: tobo Date: Tue, 13 Jan 2026 11:11:41 +0300 Subject: switch to std::atomic commit_hash:ac65b663bf44b4571b5fe124261e56dd6a43ad41 --- library/cpp/logger/rotating_file.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'library/cpp/logger/rotating_file.cpp') diff --git a/library/cpp/logger/rotating_file.cpp b/library/cpp/logger/rotating_file.cpp index bab6f0067c6..aa27e9a79bb 100644 --- a/library/cpp/logger/rotating_file.cpp +++ b/library/cpp/logger/rotating_file.cpp @@ -6,7 +6,8 @@ #include #include #include -#include + +#include /* * rotating file log @@ -29,10 +30,10 @@ public: Y_ENSURE(RotatedFilesCount_ != 0); } - inline void WriteData(const TLogRecord& rec) { - if (static_cast(AtomicGet(Size_)) > MaxSizeBytes_) { + void WriteData(const TLogRecord& rec) { + if (Size_.load() > MaxSizeBytes_) { TWriteGuard guard(Lock_); - if (static_cast(AtomicGet(Size_)) > MaxSizeBytes_) { + if (Y_LIKELY(Size_.load() > MaxSizeBytes_)) { TString newLogPath(TStringBuilder{} << Path_ << "." << RotatedFilesCount_); for (size_t fileId = RotatedFilesCount_ - 1; fileId; --fileId) { TString oldLogPath(TStringBuilder{} << Path_ << "." << fileId); @@ -41,19 +42,19 @@ public: } NFs::Rename(Path_, newLogPath); Log_.ReopenLog(); - AtomicSet(Size_, 0); + Size_.store(0); } } TReadGuard guard(Lock_); Log_.WriteData(rec); - AtomicAdd(Size_, rec.Len); + Size_ += rec.Len; } - inline void ReopenLog() { + void ReopenLog() { TWriteGuard guard(Lock_); Log_.ReopenLog(); - AtomicSet(Size_, TFileStat(Path_).Size); + Size_.store(TFileStat(Path_).Size); } private: @@ -61,7 +62,7 @@ private: TFileLogBackend Log_; const TString Path_; const ui64 MaxSizeBytes_; - TAtomic Size_; + std::atomic Size_; const ui32 RotatedFilesCount_; }; @@ -70,8 +71,7 @@ TRotatingFileLogBackend::TRotatingFileLogBackend(const TString& path, const ui64 { } -TRotatingFileLogBackend::~TRotatingFileLogBackend() { -} +TRotatingFileLogBackend::~TRotatingFileLogBackend() = default; void TRotatingFileLogBackend::WriteData(const TLogRecord& rec) { Impl_->WriteData(rec); -- cgit v1.3