thread.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. #pragma once
  2. #include "backend.h"
  3. #include <util/generic/ptr.h>
  4. #include <functional>
  5. class TThreadedLogBackend: public TLogBackend {
  6. public:
  7. TThreadedLogBackend(TLogBackend* slave);
  8. TThreadedLogBackend(TLogBackend* slave, size_t queuelen, std::function<void()> queueOverflowCallback = {});
  9. ~TThreadedLogBackend() override;
  10. void WriteData(const TLogRecord& rec) override;
  11. void ReopenLog() override;
  12. void ReopenLogNoFlush() override;
  13. size_t QueueSize() const override;
  14. // Write an emergency message when the memory allocator is corrupted.
  15. // The TThreadedLogBackend object can't be used after this method is called.
  16. void WriteEmergencyData(const TLogRecord& rec);
  17. private:
  18. class TImpl;
  19. THolder<TImpl> Impl_;
  20. };
  21. class TOwningThreadedLogBackend: private THolder<TLogBackend>, public TThreadedLogBackend {
  22. public:
  23. TOwningThreadedLogBackend(TLogBackend* slave);
  24. TOwningThreadedLogBackend(TLogBackend* slave, size_t queuelen, std::function<void()> queueOverflowCallback = {});
  25. ~TOwningThreadedLogBackend() override;
  26. };