From ed17c9a4a91617fd87256a858d4e926e220f0588 Mon Sep 17 00:00:00 2001 From: gabime Date: Tue, 2 Dec 2014 02:17:39 +0200 Subject: [PATCH] fixed async_sink to use move instead of unique_ptr --- include/spdlog/sinks/async_sink.h | 40 +++++++++++++++++-------------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/include/spdlog/sinks/async_sink.h b/include/spdlog/sinks/async_sink.h index fe87c10b..8cff37fa 100644 --- a/include/spdlog/sinks/async_sink.h +++ b/include/spdlog/sinks/async_sink.h @@ -41,6 +41,7 @@ #include "../details/blocking_queue.h" #include "../details/null_mutex.h" #include "../details/log_msg.h" +#include "../details/format.h" namespace spdlog @@ -52,7 +53,8 @@ namespace sinks class async_sink : public base_sink < details::null_mutex > //single worker thread so null_mutex { public: - using q_type = details::blocking_queue < std::unique_ptr > ; + + using q_type = details::blocking_queue < details::log_msg > ; explicit async_sink(const q_type::size_type max_queue_size); @@ -109,10 +111,10 @@ inline spdlog::sinks::async_sink::~async_sink() inline void spdlog::sinks::async_sink::_sink_it(const details::log_msg& msg) { _push_sentry(); - _q.push(std::unique_ptr(new details::log_msg(msg))); + _q.push(std::move(msg)); + } - inline void spdlog::sinks::async_sink::_thread_loop() { std::chrono::seconds pop_timeout { 1 }; @@ -124,22 +126,24 @@ inline void spdlog::sinks::async_sink::_thread_loop() { if (!_active) return; - _formatter->format(*msg); - for (auto &s : _sinks) + + try { - try - { - s->log(*msg); - } - catch (const std::exception& ex) - { - _last_backthread_ex = std::make_shared(ex.what()); - } - catch (...) - { - _last_backthread_ex = std::make_shared("Unknown exception"); - } + + _formatter->format(msg); + for (auto &s : _sinks) + s->log(msg); + } + catch (const std::exception& ex) + { + _last_backthread_ex = std::make_shared(ex.what()); + } + catch (...) + { + _last_backthread_ex = std::make_shared("Unknown exception"); + } + } } } @@ -178,7 +182,7 @@ inline void spdlog::sinks::async_sink::shutdown(const log_clock::duration& timeo _join(); } - +#include inline void spdlog::sinks::async_sink::_push_sentry() { if (_last_backthread_ex)