comparison DEPENDENCIES/generic/include/boost/log/sinks/unlocked_frontend.hpp @ 16:2665513ce2d3

Add boost headers
author Chris Cannam
date Tue, 05 Aug 2014 11:11:38 +0100
parents
children c530137014c0
comparison
equal deleted inserted replaced
15:663ca0da4350 16:2665513ce2d3
1 /*
2 * Copyright Andrey Semashev 2007 - 2013.
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)
6 */
7 /*!
8 * \file unlocked_frontend.hpp
9 * \author Andrey Semashev
10 * \date 14.07.2009
11 *
12 * The header contains declaration of an unlocked sink frontend.
13 */
14
15 #ifndef BOOST_LOG_SINKS_UNLOCKED_FRONTEND_HPP_INCLUDED_
16 #define BOOST_LOG_SINKS_UNLOCKED_FRONTEND_HPP_INCLUDED_
17
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/log/detail/config.hpp>
22 #include <boost/log/detail/parameter_tools.hpp>
23 #include <boost/log/detail/fake_mutex.hpp>
24 #include <boost/log/sinks/basic_sink_frontend.hpp>
25 #include <boost/log/sinks/frontend_requirements.hpp>
26 #include <boost/log/detail/header.hpp>
27
28 #ifdef BOOST_HAS_PRAGMA_ONCE
29 #pragma once
30 #endif
31
32 namespace boost {
33
34 BOOST_LOG_OPEN_NAMESPACE
35
36 namespace sinks {
37
38 #ifndef BOOST_LOG_DOXYGEN_PASS
39
40 #define BOOST_LOG_SINK_CTOR_FORWARD_INTERNAL(z, n, types)\
41 template< BOOST_PP_ENUM_PARAMS(n, typename T) >\
42 explicit unlocked_sink(BOOST_PP_ENUM_BINARY_PARAMS(n, T, const& arg)) :\
43 base_type(false),\
44 m_pBackend(boost::make_shared< sink_backend_type >(BOOST_PP_ENUM_PARAMS(n, arg))) {}
45
46 #endif // BOOST_LOG_DOXYGEN_PASS
47
48 /*!
49 * \brief Non-blocking logging sink frontend
50 *
51 * The sink frontend does not perform thread synchronization and
52 * simply passes logging records to the sink backend.
53 */
54 template< typename SinkBackendT >
55 class unlocked_sink :
56 public aux::make_sink_frontend_base< SinkBackendT >::type
57 {
58 typedef typename aux::make_sink_frontend_base< SinkBackendT >::type base_type;
59
60 public:
61 //! Sink implementation type
62 typedef SinkBackendT sink_backend_type;
63 //! \cond
64 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");
65 //! \endcond
66
67 //! Type of pointer to the backend
68 typedef shared_ptr< sink_backend_type > locked_backend_ptr;
69
70 private:
71 //! Pointer to the backend
72 const shared_ptr< sink_backend_type > m_pBackend;
73
74 public:
75 /*!
76 * Default constructor. Constructs the sink backend instance.
77 * Requires the backend to be default-constructible.
78 */
79 unlocked_sink() :
80 base_type(false),
81 m_pBackend(boost::make_shared< sink_backend_type >())
82 {
83 }
84 /*!
85 * Constructor attaches user-constructed backend instance
86 *
87 * \param backend Pointer to the backend instance
88 *
89 * \pre \a backend is not \c NULL.
90 */
91 explicit unlocked_sink(shared_ptr< sink_backend_type > const& backend) :
92 base_type(false),
93 m_pBackend(backend)
94 {
95 }
96
97 // Constructors that pass arbitrary parameters to the backend constructor
98 BOOST_LOG_PARAMETRIZED_CONSTRUCTORS_GEN(BOOST_LOG_SINK_CTOR_FORWARD_INTERNAL, ~)
99
100 /*!
101 * Locking accessor to the attached backend.
102 *
103 * \note Does not do any actual locking, provided only for interface consistency
104 * with other frontends.
105 */
106 locked_backend_ptr locked_backend()
107 {
108 return m_pBackend;
109 }
110
111 /*!
112 * Passes the log record to the backend
113 */
114 void consume(record_view const& rec)
115 {
116 boost::log::aux::fake_mutex m;
117 base_type::feed_record(rec, m, *m_pBackend);
118 }
119
120 /*!
121 * The method performs flushing of any internal buffers that may hold log records. The method
122 * may take considerable time to complete and may block both the calling thread and threads
123 * attempting to put new records into the sink while this call is in progress.
124 */
125 void flush()
126 {
127 boost::log::aux::fake_mutex m;
128 base_type::flush_backend(m, *m_pBackend);
129 }
130 };
131
132 #undef BOOST_LOG_SINK_CTOR_FORWARD_INTERNAL
133
134 } // namespace sinks
135
136 BOOST_LOG_CLOSE_NAMESPACE // namespace log
137
138 } // namespace boost
139
140 #include <boost/log/detail/footer.hpp>
141
142 #endif // BOOST_LOG_SINKS_UNLOCKED_FRONTEND_HPP_INCLUDED_