comparison DEPENDENCIES/generic/include/boost/log/sinks/bounded_ordering_queue.hpp @ 101:c530137014c0

Update Boost headers (1.58.0)
author Chris Cannam
date Mon, 07 Sep 2015 11:12:49 +0100
parents 2665513ce2d3
children
comparison
equal deleted inserted replaced
100:793467b5e61c 101:c530137014c0
1 /* 1 /*
2 * Copyright Andrey Semashev 2007 - 2013. 2 * Copyright Andrey Semashev 2007 - 2015.
3 * Distributed under the Boost Software License, Version 1.0. 3 * Distributed under the Boost Software License, Version 1.0.
4 * (See accompanying file LICENSE_1_0.txt or copy at 4 * (See accompanying file LICENSE_1_0.txt or copy at
5 * http://www.boost.org/LICENSE_1_0.txt) 5 * http://www.boost.org/LICENSE_1_0.txt)
6 */ 6 */
7 /*! 7 /*!
28 28
29 #include <cstddef> 29 #include <cstddef>
30 #include <queue> 30 #include <queue>
31 #include <vector> 31 #include <vector>
32 #include <boost/cstdint.hpp> 32 #include <boost/cstdint.hpp>
33 #include <boost/move/core.hpp>
34 #include <boost/move/utility.hpp>
35 #include <boost/thread/locks.hpp> 33 #include <boost/thread/locks.hpp>
36 #include <boost/thread/mutex.hpp> 34 #include <boost/thread/mutex.hpp>
37 #include <boost/thread/condition_variable.hpp> 35 #include <boost/thread/condition_variable.hpp>
38 #include <boost/thread/thread_time.hpp> 36 #include <boost/thread/thread_time.hpp>
39 #include <boost/date_time/posix_time/posix_time_types.hpp> 37 #include <boost/date_time/posix_time/posix_time_types.hpp>
40 #include <boost/log/detail/timestamp.hpp> 38 #include <boost/log/detail/timestamp.hpp>
39 #include <boost/log/detail/enqueued_record.hpp>
41 #include <boost/log/keywords/order.hpp> 40 #include <boost/log/keywords/order.hpp>
42 #include <boost/log/keywords/ordering_window.hpp> 41 #include <boost/log/keywords/ordering_window.hpp>
43 #include <boost/log/core/record_view.hpp> 42 #include <boost/log/core/record_view.hpp>
44 #include <boost/log/detail/header.hpp> 43 #include <boost/log/detail/header.hpp>
45 44
73 private OverflowStrategyT 72 private OverflowStrategyT
74 { 73 {
75 private: 74 private:
76 typedef OverflowStrategyT overflow_strategy; 75 typedef OverflowStrategyT overflow_strategy;
77 typedef boost::mutex mutex_type; 76 typedef boost::mutex mutex_type;
78 77 typedef sinks::aux::enqueued_record enqueued_record;
79 //! Log record with enqueueing timestamp
80 class enqueued_record
81 {
82 BOOST_COPYABLE_AND_MOVABLE(enqueued_record)
83
84 public:
85 //! Ordering predicate
86 struct order :
87 public OrderT
88 {
89 typedef typename OrderT::result_type result_type;
90
91 order() {}
92 order(order const& that) : OrderT(static_cast< OrderT const& >(that)) {}
93 order(OrderT const& that) : OrderT(that) {}
94
95 result_type operator() (enqueued_record const& left, enqueued_record const& right) const
96 {
97 // std::priority_queue requires ordering with semantics of std::greater, so we swap arguments
98 return OrderT::operator() (right.m_record, left.m_record);
99 }
100 };
101
102 boost::log::aux::timestamp m_timestamp;
103 record_view m_record;
104
105 enqueued_record(enqueued_record const& that) : m_timestamp(that.m_timestamp), m_record(that.m_record)
106 {
107 }
108 enqueued_record(BOOST_RV_REF(enqueued_record) that) :
109 m_timestamp(that.m_timestamp),
110 m_record(boost::move(that.m_record))
111 {
112 }
113 explicit enqueued_record(record_view const& rec) :
114 m_timestamp(boost::log::aux::get_timestamp()),
115 m_record(rec)
116 {
117 }
118 enqueued_record& operator= (BOOST_COPY_ASSIGN_REF(enqueued_record) that)
119 {
120 m_timestamp = that.m_timestamp;
121 m_record = that.m_record;
122 return *this;
123 }
124 enqueued_record& operator= (BOOST_RV_REF(enqueued_record) that)
125 {
126 m_timestamp = that.m_timestamp;
127 m_record = boost::move(that.m_record);
128 return *this;
129 }
130 };
131 78
132 typedef std::priority_queue< 79 typedef std::priority_queue<
133 enqueued_record, 80 enqueued_record,
134 std::vector< enqueued_record >, 81 std::vector< enqueued_record >,
135 typename enqueued_record::order 82 enqueued_record::order< OrderT >
136 > queue_type; 83 > queue_type;
137 84
138 private: 85 private:
139 //! Ordering window duration, in milliseconds 86 //! Ordering window duration, in milliseconds
140 const uint64_t m_ordering_window; 87 const uint64_t m_ordering_window;
231 if (static_cast< uint64_t >((now - elem.m_timestamp).milliseconds()) >= m_ordering_window) 178 if (static_cast< uint64_t >((now - elem.m_timestamp).milliseconds()) >= m_ordering_window)
232 { 179 {
233 // We got a new element 180 // We got a new element
234 rec = elem.m_record; 181 rec = elem.m_record;
235 m_queue.pop(); 182 m_queue.pop();
236 if (size == MaxQueueSizeV) 183 overflow_strategy::on_queue_space_available();
237 overflow_strategy::on_queue_space_available();
238 return true; 184 return true;
239 } 185 }
240 } 186 }
241 187
242 return false; 188 return false;
250 if (size > 0) 196 if (size > 0)
251 { 197 {
252 enqueued_record const& elem = m_queue.top(); 198 enqueued_record const& elem = m_queue.top();
253 rec = elem.m_record; 199 rec = elem.m_record;
254 m_queue.pop(); 200 m_queue.pop();
255 if (size == MaxQueueSizeV) 201 overflow_strategy::on_queue_space_available();
256 overflow_strategy::on_queue_space_available();
257 return true; 202 return true;
258 } 203 }
259 204
260 return false; 205 return false;
261 } 206 }
275 const uint64_t difference = (now - elem.m_timestamp).milliseconds(); 220 const uint64_t difference = (now - elem.m_timestamp).milliseconds();
276 if (difference >= m_ordering_window) 221 if (difference >= m_ordering_window)
277 { 222 {
278 rec = elem.m_record; 223 rec = elem.m_record;
279 m_queue.pop(); 224 m_queue.pop();
280 if (size == MaxQueueSizeV) 225 overflow_strategy::on_queue_space_available();
281 overflow_strategy::on_queue_space_available();
282 return true; 226 return true;
283 } 227 }
284 else 228 else
285 { 229 {
286 // Wait until the element becomes ready to be processed 230 // Wait until the element becomes ready to be processed