Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:39:25

0001 /*
0002  *          Copyright Andrey Semashev 2007 - 2015.
0003  * Distributed under the Boost Software License, Version 1.0.
0004  *    (See accompanying file LICENSE_1_0.txt or copy at
0005  *          http://www.boost.org/LICENSE_1_0.txt)
0006  */
0007 /*!
0008  * \file   unlocked_frontend.hpp
0009  * \author Andrey Semashev
0010  * \date   14.07.2009
0011  *
0012  * The header contains declaration of an unlocked sink frontend.
0013  */
0014 
0015 #ifndef BOOST_LOG_SINKS_UNLOCKED_FRONTEND_HPP_INCLUDED_
0016 #define BOOST_LOG_SINKS_UNLOCKED_FRONTEND_HPP_INCLUDED_
0017 
0018 #include <boost/smart_ptr/shared_ptr.hpp>
0019 #include <boost/smart_ptr/make_shared_object.hpp>
0020 #include <boost/preprocessor/control/if.hpp>
0021 #include <boost/preprocessor/comparison/equal.hpp>
0022 #include <boost/log/detail/config.hpp>
0023 #include <boost/log/detail/parameter_tools.hpp>
0024 #include <boost/log/detail/fake_mutex.hpp>
0025 #include <boost/log/sinks/basic_sink_frontend.hpp>
0026 #include <boost/log/sinks/frontend_requirements.hpp>
0027 #include <boost/log/detail/header.hpp>
0028 
0029 #ifdef BOOST_HAS_PRAGMA_ONCE
0030 #pragma once
0031 #endif
0032 
0033 namespace boost {
0034 
0035 BOOST_LOG_OPEN_NAMESPACE
0036 
0037 namespace sinks {
0038 
0039 #ifndef BOOST_LOG_DOXYGEN_PASS
0040 
0041 #define BOOST_LOG_SINK_CTOR_FORWARD_INTERNAL_1(z, n, data)\
0042     template< typename T0 >\
0043     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()) :\
0044         base_type(false),\
0045         m_pBackend(boost::make_shared< sink_backend_type >(arg0)) {}
0046 
0047 #define BOOST_LOG_SINK_CTOR_FORWARD_INTERNAL_N(z, n, data)\
0048     template< BOOST_PP_ENUM_PARAMS_Z(z, n, typename T) >\
0049     explicit unlocked_sink(BOOST_PP_ENUM_BINARY_PARAMS_Z(z, n, T, const& arg)) :\
0050         base_type(false),\
0051         m_pBackend(boost::make_shared< sink_backend_type >(BOOST_PP_ENUM_PARAMS_Z(z, n, arg))) {}
0052 
0053 #define BOOST_LOG_SINK_CTOR_FORWARD_INTERNAL(z, n, data)\
0054     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)
0055 
0056 #endif // BOOST_LOG_DOXYGEN_PASS
0057 
0058 /*!
0059  * \brief Non-blocking logging sink frontend
0060  *
0061  * The sink frontend does not perform thread synchronization and
0062  * simply passes logging records to the sink backend.
0063  */
0064 template< typename SinkBackendT >
0065 class unlocked_sink :
0066     public aux::make_sink_frontend_base< SinkBackendT >::type
0067 {
0068     typedef typename aux::make_sink_frontend_base< SinkBackendT >::type base_type;
0069 
0070 public:
0071     //! Sink implementation type
0072     typedef SinkBackendT sink_backend_type;
0073     //! \cond
0074     static_assert(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");
0075     //! \endcond
0076 
0077     //! Type of pointer to the backend
0078     typedef shared_ptr< sink_backend_type > locked_backend_ptr;
0079 
0080 private:
0081     //! Pointer to the backend
0082     const shared_ptr< sink_backend_type > m_pBackend;
0083 
0084 public:
0085     /*!
0086      * Default constructor. Constructs the sink backend instance.
0087      * Requires the backend to be default-constructible.
0088      */
0089     unlocked_sink() :
0090         base_type(false),
0091         m_pBackend(boost::make_shared< sink_backend_type >())
0092     {
0093     }
0094     /*!
0095      * Constructor attaches user-constructed backend instance
0096      *
0097      * \param backend Pointer to the backend instance
0098      *
0099      * \pre \a backend is not \c NULL.
0100      */
0101     explicit unlocked_sink(shared_ptr< sink_backend_type > const& backend) :
0102         base_type(false),
0103         m_pBackend(backend)
0104     {
0105     }
0106 
0107     /*!
0108      * Constructor that passes arbitrary named parameters to the interprocess sink backend constructor.
0109      * Refer to the backend documentation for the list of supported parameters.
0110      */
0111 #ifndef BOOST_LOG_DOXYGEN_PASS
0112     BOOST_LOG_PARAMETRIZED_CONSTRUCTORS_GEN(BOOST_LOG_SINK_CTOR_FORWARD_INTERNAL, ~)
0113 #else
0114     template< typename... Args >
0115     explicit unlocked_sink(Args&&... args);
0116 #endif
0117 
0118     /*!
0119      * Locking accessor to the attached backend.
0120      *
0121      * \note Does not do any actual locking, provided only for interface consistency
0122      *       with other frontends.
0123      */
0124     locked_backend_ptr locked_backend()
0125     {
0126         return m_pBackend;
0127     }
0128 
0129     /*!
0130      * Passes the log record to the backend
0131      */
0132     void consume(record_view const& rec)
0133     {
0134         boost::log::aux::fake_mutex m;
0135         base_type::feed_record(rec, m, *m_pBackend);
0136     }
0137 
0138     /*!
0139      * The method performs flushing of any internal buffers that may hold log records. The method
0140      * may take considerable time to complete and may block both the calling thread and threads
0141      * attempting to put new records into the sink while this call is in progress.
0142      */
0143     void flush()
0144     {
0145         boost::log::aux::fake_mutex m;
0146         base_type::flush_backend(m, *m_pBackend);
0147     }
0148 };
0149 
0150 #undef BOOST_LOG_SINK_CTOR_FORWARD_INTERNAL_1
0151 #undef BOOST_LOG_SINK_CTOR_FORWARD_INTERNAL_N
0152 #undef BOOST_LOG_SINK_CTOR_FORWARD_INTERNAL
0153 
0154 } // namespace sinks
0155 
0156 BOOST_LOG_CLOSE_NAMESPACE // namespace log
0157 
0158 } // namespace boost
0159 
0160 #include <boost/log/detail/footer.hpp>
0161 
0162 #endif // BOOST_LOG_SINKS_UNLOCKED_FRONTEND_HPP_INCLUDED_