diff options
author | Anton Samokhvalov <pg83@yandex.ru> | 2022-02-10 16:45:17 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:17 +0300 |
commit | d3a398281c6fd1d3672036cb2d63f842d2cb28c5 (patch) | |
tree | dd4bd3ca0f36b817e96812825ffaf10d645803f2 /library/cpp/logger/thread.cpp | |
parent | 72cb13b4aff9bc9cf22e49251bc8fd143f82538f (diff) | |
download | ydb-d3a398281c6fd1d3672036cb2d63f842d2cb28c5.tar.gz |
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/logger/thread.cpp')
-rw-r--r-- | library/cpp/logger/thread.cpp | 224 |
1 files changed, 112 insertions, 112 deletions
diff --git a/library/cpp/logger/thread.cpp b/library/cpp/logger/thread.cpp index a2650f195a..0ccf9e374b 100644 --- a/library/cpp/logger/thread.cpp +++ b/library/cpp/logger/thread.cpp @@ -1,77 +1,77 @@ -#include "thread.h" -#include "record.h" - +#include "thread.h" +#include "record.h" + #include <util/thread/pool.h> -#include <util/system/event.h> -#include <util/memory/addstorage.h> -#include <util/generic/ptr.h> -#include <util/generic/yexception.h> - -class TThreadedLogBackend::TImpl { - class TRec: public IObjectInQueue, public TAdditionalStorage<TRec>, public TLogRecord { - public: - inline TRec(TImpl* parent, const TLogRecord& rec) - : TLogRecord(rec.Priority, (const char*)AdditionalData(), rec.Len) - , Parent_(parent) - { - memcpy(AdditionalData(), rec.Data, rec.Len); - } - - inline ~TRec() override { - } - - private: - void Process(void* /*tsr*/) override { - THolder<TRec> This(this); - - Parent_->Slave_->WriteData(*this); - } - - private: - TImpl* Parent_; - }; - +#include <util/system/event.h> +#include <util/memory/addstorage.h> +#include <util/generic/ptr.h> +#include <util/generic/yexception.h> + +class TThreadedLogBackend::TImpl { + class TRec: public IObjectInQueue, public TAdditionalStorage<TRec>, public TLogRecord { + public: + inline TRec(TImpl* parent, const TLogRecord& rec) + : TLogRecord(rec.Priority, (const char*)AdditionalData(), rec.Len) + , Parent_(parent) + { + memcpy(AdditionalData(), rec.Data, rec.Len); + } + + inline ~TRec() override { + } + + private: + void Process(void* /*tsr*/) override { + THolder<TRec> This(this); + + Parent_->Slave_->WriteData(*this); + } + + private: + TImpl* Parent_; + }; + class TReopener: public IObjectInQueue, public TSystemEvent, public TAtomicRefCount<TReopener> { - public: - inline TReopener(TImpl* parent) - : Parent_(parent) - { - Ref(); - } - - inline ~TReopener() override { - } - - private: - void Process(void* /*tsr*/) override { - try { - Parent_->Slave_->ReopenLog(); - } catch (...) { - } - - Signal(); - UnRef(); - } - - private: - TImpl* Parent_; - }; - -public: + public: + inline TReopener(TImpl* parent) + : Parent_(parent) + { + Ref(); + } + + inline ~TReopener() override { + } + + private: + void Process(void* /*tsr*/) override { + try { + Parent_->Slave_->ReopenLog(); + } catch (...) { + } + + Signal(); + UnRef(); + } + + private: + TImpl* Parent_; + }; + +public: inline TImpl(TLogBackend* slave, size_t queuelen, std::function<void()> queueOverflowCallback = {}) - : Slave_(slave) + : Slave_(slave) , QueueOverflowCallback_(std::move(queueOverflowCallback)) - { - Queue_.Start(1, queuelen); - } - - inline ~TImpl() { - Queue_.Stop(); - } - - inline void WriteData(const TLogRecord& rec) { - THolder<TRec> obj(new (rec.Len) TRec(this, rec)); - + { + Queue_.Start(1, queuelen); + } + + inline ~TImpl() { + Queue_.Stop(); + } + + inline void WriteData(const TLogRecord& rec) { + THolder<TRec> obj(new (rec.Len) TRec(this, rec)); + if (Queue_.Add(obj.Get())) { Y_UNUSED(obj.Release()); return; @@ -80,28 +80,28 @@ public: if (QueueOverflowCallback_) { QueueOverflowCallback_(); } else { - ythrow yexception() << "log queue exhausted"; + ythrow yexception() << "log queue exhausted"; } - } - - // Write an emergency message when the memory allocator is corrupted. - // The TThreadedLogBackend object can't be used after this method is called. - inline void WriteEmergencyData(const TLogRecord& rec) noexcept { - Queue_.Stop(); - Slave_->WriteData(rec); - } - - inline void ReopenLog() { - TIntrusivePtr<TReopener> reopener(new TReopener(this)); - - if (!Queue_.Add(reopener.Get())) { - reopener->UnRef(); // Ref() was called in constructor - ythrow yexception() << "log queue exhausted"; - } - - reopener->Wait(); - } - + } + + // Write an emergency message when the memory allocator is corrupted. + // The TThreadedLogBackend object can't be used after this method is called. + inline void WriteEmergencyData(const TLogRecord& rec) noexcept { + Queue_.Stop(); + Slave_->WriteData(rec); + } + + inline void ReopenLog() { + TIntrusivePtr<TReopener> reopener(new TReopener(this)); + + if (!Queue_.Add(reopener.Get())) { + reopener->UnRef(); // Ref() was called in constructor + ythrow yexception() << "log queue exhausted"; + } + + reopener->Wait(); + } + inline void ReopenLogNoFlush() { Slave_->ReopenLogNoFlush(); } @@ -110,32 +110,32 @@ public: return Queue_.Size(); } -private: - TLogBackend* Slave_; +private: + TLogBackend* Slave_; TThreadPool Queue_{"ThreadedLogBack"}; const std::function<void()> QueueOverflowCallback_; -}; - -TThreadedLogBackend::TThreadedLogBackend(TLogBackend* slave) - : Impl_(new TImpl(slave, 0)) -{ -} - +}; + +TThreadedLogBackend::TThreadedLogBackend(TLogBackend* slave) + : Impl_(new TImpl(slave, 0)) +{ +} + TThreadedLogBackend::TThreadedLogBackend(TLogBackend* slave, size_t queuelen, std::function<void()> queueOverflowCallback) : Impl_(new TImpl(slave, queuelen, std::move(queueOverflowCallback))) -{ -} - +{ +} + TThreadedLogBackend::~TThreadedLogBackend() { -} - -void TThreadedLogBackend::WriteData(const TLogRecord& rec) { - Impl_->WriteData(rec); -} - -void TThreadedLogBackend::ReopenLog() { - Impl_->ReopenLog(); -} +} + +void TThreadedLogBackend::WriteData(const TLogRecord& rec) { + Impl_->WriteData(rec); +} + +void TThreadedLogBackend::ReopenLog() { + Impl_->ReopenLog(); +} void TThreadedLogBackend::ReopenLogNoFlush() { Impl_->ReopenLogNoFlush(); |