diff options
| author | tobo <[email protected]> | 2026-01-13 11:11:41 +0300 |
|---|---|---|
| committer | tobo <[email protected]> | 2026-01-13 11:32:52 +0300 |
| commit | 2473768fdb0aaa0dbb65606bf330f4e8154889de (patch) | |
| tree | 487949276dae72101171d29b2b8bc224e44c216d /library/cpp/logger/rotating_file.cpp | |
| parent | 05c0c8a128582bb1391c8e78f3e9269b9876e079 (diff) | |
switch to std::atomic
commit_hash:ac65b663bf44b4571b5fe124261e56dd6a43ad41
Diffstat (limited to 'library/cpp/logger/rotating_file.cpp')
| -rw-r--r-- | library/cpp/logger/rotating_file.cpp | 22 |
1 files changed, 11 insertions, 11 deletions
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 <util/system/fstat.h> #include <util/system/rwlock.h> #include <util/system/fs.h> -#include <library/cpp/deprecated/atomic/atomic.h> + +#include <atomic> /* * rotating file log @@ -29,10 +30,10 @@ public: Y_ENSURE(RotatedFilesCount_ != 0); } - inline void WriteData(const TLogRecord& rec) { - if (static_cast<ui64>(AtomicGet(Size_)) > MaxSizeBytes_) { + void WriteData(const TLogRecord& rec) { + if (Size_.load() > MaxSizeBytes_) { TWriteGuard guard(Lock_); - if (static_cast<ui64>(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<ui64> 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); |
