...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
boost::log::sinks::bounded_ordering_queue — Bounded ordering log record queueing strategy.
// In header: <boost/log/sinks/bounded_ordering_queue.hpp> template<typename OrderT, std::size_t MaxQueueSizeV, typename OverflowStrategyT> class bounded_ordering_queue : private OverflowStrategyT { public: // member classes/structs/unions // Log record with enqueueing timestamp. class enqueued_record { public: // member classes/structs/unions // Ordering predicate. struct order : public OrderT { // types typedef OrderT::result_type result_type; // construct/copy/destruct order(); order(order const &); order(OrderT const &); // public member functions result_type operator()(enqueued_record const &, enqueued_record const &) const; }; // construct/copy/destruct enqueued_record(enqueued_record const &); enqueued_record(enqueued_record &&); explicit enqueued_record(record_view const &); enqueued_record& operator=(enqueued_record const &); enqueued_record& operator=(enqueued_record &&); // public data members unspecified m_timestamp; record_view m_record; }; // construct/copy/destruct template<typename ArgsT> explicit bounded_ordering_queue(ArgsT const &); // public member functions posix_time::time_duration get_ordering_window() const; // public static functions static posix_time::time_duration get_default_ordering_window(); // protected member functions void enqueue(record_view const &); bool try_enqueue(record_view const &); bool try_dequeue_ready(record_view &); bool try_dequeue(record_view &); bool dequeue_ready(record_view &); void interrupt_dequeue(); };
The bounded_ordering_queue
class is intended to be used with the asynchronous_sink
frontend as a log record queueing strategy.
This strategy provides the following properties to the record queueing mechanism:
The queue has limited capacity specified by the MaxQueueSizeV
template parameter.
Upon reaching the size limit, the queue invokes the overflow handling strategy specified in the OverflowStrategyT
template parameter to handle the situation. The library provides overflow handling strategies for most common cases: drop_on_overflow
will silently discard the log record, and block_on_overflow
will put the enqueueing thread to wait until there is space in the queue.
The queue has a fixed latency window. This means that each log record put into the queue will normally not be dequeued for a certain period of time.
The queue performs stable record ordering within the latency window. The ordering predicate can be specified in the OrderT
template parameter.
bounded_ordering_queue
protected member functionsvoid enqueue(record_view const & rec);Enqueues log record to the queue.
bool try_enqueue(record_view const & rec);Attempts to enqueue log record to the queue.
bool try_dequeue_ready(record_view & rec);Attempts to dequeue a log record ready for processing from the queue, does not block if the queue is empty.
bool try_dequeue(record_view & rec);Attempts to dequeue log record from the queue, does not block if the queue is empty.
bool dequeue_ready(record_view & rec);Dequeues log record from the queue, blocks if the queue is empty.
void interrupt_dequeue();Wakes a thread possibly blocked in the
dequeue
method.