2 * Copyright Andrey Semashev 2007 - 2015.
3 * Distributed under the Boost Software License, Version 1.0.
4 * (See accompanying file LICENSE_1_0.txt or copy at
5 * http://www.boost.org/LICENSE_1_0.txt)
8 * \file unlocked_frontend.hpp
9 * \author Andrey Semashev
12 * The header contains declaration of an unlocked sink frontend.
15 #ifndef BOOST_LOG_SINKS_UNLOCKED_FRONTEND_HPP_INCLUDED_
16 #define BOOST_LOG_SINKS_UNLOCKED_FRONTEND_HPP_INCLUDED_
18 #include <boost/static_assert.hpp>
19 #include <boost/smart_ptr/shared_ptr.hpp>
20 #include <boost/smart_ptr/make_shared_object.hpp>
21 #include <boost/preprocessor/control/if.hpp>
22 #include <boost/preprocessor/comparison/equal.hpp>
23 #include <boost/log/detail/config.hpp>
24 #include <boost/log/detail/parameter_tools.hpp>
25 #include <boost/log/detail/fake_mutex.hpp>
26 #include <boost/log/sinks/basic_sink_frontend.hpp>
27 #include <boost/log/sinks/frontend_requirements.hpp>
28 #include <boost/log/detail/header.hpp>
30 #ifdef BOOST_HAS_PRAGMA_ONCE
36 BOOST_LOG_OPEN_NAMESPACE
40 #ifndef BOOST_LOG_DOXYGEN_PASS
42 #define BOOST_LOG_SINK_CTOR_FORWARD_INTERNAL_1(z, n, data)\
43 template< typename T0 >\
44 explicit unlocked_sink(T0 const& arg0, typename boost::log::aux::enable_if_named_parameters< T0, boost::log::aux::sfinae_dummy >::type = boost::log::aux::sfinae_dummy()) :\
46 m_pBackend(boost::make_shared< sink_backend_type >(arg0)) {}
48 #define BOOST_LOG_SINK_CTOR_FORWARD_INTERNAL_N(z, n, data)\
49 template< BOOST_PP_ENUM_PARAMS_Z(z, n, typename T) >\
50 explicit unlocked_sink(BOOST_PP_ENUM_BINARY_PARAMS_Z(z, n, T, const& arg)) :\
52 m_pBackend(boost::make_shared< sink_backend_type >(BOOST_PP_ENUM_PARAMS_Z(z, n, arg))) {}
54 #define BOOST_LOG_SINK_CTOR_FORWARD_INTERNAL(z, n, data)\
55 BOOST_PP_IF(BOOST_PP_EQUAL(n, 1), BOOST_LOG_SINK_CTOR_FORWARD_INTERNAL_1, BOOST_LOG_SINK_CTOR_FORWARD_INTERNAL_N)(z, n, data)
57 #endif // BOOST_LOG_DOXYGEN_PASS
60 * \brief Non-blocking logging sink frontend
62 * The sink frontend does not perform thread synchronization and
63 * simply passes logging records to the sink backend.
65 template< typename SinkBackendT >
67 public aux::make_sink_frontend_base< SinkBackendT >::type
69 typedef typename aux::make_sink_frontend_base< SinkBackendT >::type base_type;
72 //! Sink implementation type
73 typedef SinkBackendT sink_backend_type;
75 BOOST_STATIC_ASSERT_MSG((has_requirement< typename sink_backend_type::frontend_requirements, concurrent_feeding >::value), "Unlocked sink frontend is incompatible with the specified backend: thread synchronization requirements are not met");
78 //! Type of pointer to the backend
79 typedef shared_ptr< sink_backend_type > locked_backend_ptr;
82 //! Pointer to the backend
83 const shared_ptr< sink_backend_type > m_pBackend;
87 * Default constructor. Constructs the sink backend instance.
88 * Requires the backend to be default-constructible.
92 m_pBackend(boost::make_shared< sink_backend_type >())
96 * Constructor attaches user-constructed backend instance
98 * \param backend Pointer to the backend instance
100 * \pre \a backend is not \c NULL.
102 explicit unlocked_sink(shared_ptr< sink_backend_type > const& backend) :
109 * Constructor that passes arbitrary named parameters to the interprocess sink backend constructor.
110 * Refer to the backend documentation for the list of supported parameters.
112 #ifndef BOOST_LOG_DOXYGEN_PASS
113 BOOST_LOG_PARAMETRIZED_CONSTRUCTORS_GEN(BOOST_LOG_SINK_CTOR_FORWARD_INTERNAL, ~)
115 template< typename... Args >
116 explicit unlocked_sink(Args&&... args);
120 * Locking accessor to the attached backend.
122 * \note Does not do any actual locking, provided only for interface consistency
123 * with other frontends.
125 locked_backend_ptr locked_backend()
131 * Passes the log record to the backend
133 void consume(record_view const& rec)
135 boost::log::aux::fake_mutex m;
136 base_type::feed_record(rec, m, *m_pBackend);
140 * The method performs flushing of any internal buffers that may hold log records. The method
141 * may take considerable time to complete and may block both the calling thread and threads
142 * attempting to put new records into the sink while this call is in progress.
146 boost::log::aux::fake_mutex m;
147 base_type::flush_backend(m, *m_pBackend);
151 #undef BOOST_LOG_SINK_CTOR_FORWARD_INTERNAL_1
152 #undef BOOST_LOG_SINK_CTOR_FORWARD_INTERNAL_N
153 #undef BOOST_LOG_SINK_CTOR_FORWARD_INTERNAL
157 BOOST_LOG_CLOSE_NAMESPACE // namespace log
161 #include <boost/log/detail/footer.hpp>
163 #endif // BOOST_LOG_SINKS_UNLOCKED_FRONTEND_HPP_INCLUDED_