diff options
Diffstat (limited to 'boost/log/sinks/basic_sink_frontend.hpp')
-rw-r--r-- | boost/log/sinks/basic_sink_frontend.hpp | 41 |
1 files changed, 29 insertions, 12 deletions
diff --git a/boost/log/sinks/basic_sink_frontend.hpp b/boost/log/sinks/basic_sink_frontend.hpp index 965451c7a8..3686bc5917 100644 --- a/boost/log/sinks/basic_sink_frontend.hpp +++ b/boost/log/sinks/basic_sink_frontend.hpp @@ -17,7 +17,6 @@ #include <boost/mpl/bool.hpp> #include <boost/log/detail/config.hpp> -#include <boost/log/detail/cleanup_scope_guard.hpp> #include <boost/log/detail/code_conversion.hpp> #include <boost/log/detail/attachable_sstream_buf.hpp> #include <boost/log/detail/fake_mutex.hpp> @@ -29,7 +28,6 @@ #if !defined(BOOST_LOG_NO_THREADS) #include <boost/thread/exceptions.hpp> #include <boost/thread/tss.hpp> -#include <boost/thread/locks.hpp> #include <boost/log/detail/locks.hpp> #include <boost/log/detail/light_rw_mutex.hpp> #endif // !defined(BOOST_LOG_NO_THREADS) @@ -186,13 +184,10 @@ protected: bool try_feed_record(record_view const& rec, BackendMutexT& backend_mutex, BackendT& backend) { #if !defined(BOOST_LOG_NO_THREADS) - unique_lock< BackendMutexT > lock; try { - unique_lock< BackendMutexT > tmp_lock(backend_mutex, try_to_lock); - if (!tmp_lock.owns_lock()) + if (!backend_mutex.try_lock()) return false; - lock.swap(tmp_lock); } catch (thread_interrupted&) { @@ -206,6 +201,8 @@ protected: this->exception_handler()(); return false; } + + boost::log::aux::exclusive_auto_unlocker< BackendMutexT > unlocker(backend_mutex); #endif // No need to lock anything in the feed_record method boost::log::aux::fake_mutex m; @@ -280,6 +277,28 @@ protected: private: struct formatting_context { + class cleanup_guard + { + private: + formatting_context& m_context; + + public: + explicit cleanup_guard(formatting_context& ctx) BOOST_NOEXCEPT : m_context(ctx) + { + } + + ~cleanup_guard() + { + m_context.m_FormattedRecord.clear(); + m_context.m_FormattingStream.rdbuf()->max_size(m_context.m_FormattedRecord.max_size()); + m_context.m_FormattingStream.rdbuf()->storage_overflow(false); + m_context.m_FormattingStream.clear(); + } + + BOOST_DELETED_FUNCTION(cleanup_guard(cleanup_guard const&)) + BOOST_DELETED_FUNCTION(cleanup_guard& operator=(cleanup_guard const&)) + }; + #if !defined(BOOST_LOG_NO_THREADS) //! Object version const unsigned int m_Version; @@ -431,8 +450,7 @@ protected: context = &m_Context; #endif - boost::log::aux::cleanup_guard< stream_type > cleanup1(context->m_FormattingStream); - boost::log::aux::cleanup_guard< string_type > cleanup2(context->m_FormattedRecord); + typename formatting_context::cleanup_guard cleanup(*context); try { @@ -464,13 +482,10 @@ protected: bool try_feed_record(record_view const& rec, BackendMutexT& backend_mutex, BackendT& backend) { #if !defined(BOOST_LOG_NO_THREADS) - unique_lock< BackendMutexT > lock; try { - unique_lock< BackendMutexT > tmp_lock(backend_mutex, try_to_lock); - if (!tmp_lock.owns_lock()) + if (!backend_mutex.try_lock()) return false; - lock.swap(tmp_lock); } catch (thread_interrupted&) { @@ -484,6 +499,8 @@ protected: this->exception_handler()(); return false; } + + boost::log::aux::exclusive_auto_unlocker< BackendMutexT > unlocker(backend_mutex); #endif // No need to lock anything in the feed_record method boost::log::aux::fake_mutex m; |