File indexing completed on 2025-01-18 09:39:25
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #ifndef BOOST_LOG_SINKS_UNBOUNDED_FIFO_QUEUE_HPP_INCLUDED_
0017 #define BOOST_LOG_SINKS_UNBOUNDED_FIFO_QUEUE_HPP_INCLUDED_
0018
0019 #include <boost/log/detail/config.hpp>
0020
0021 #ifdef BOOST_HAS_PRAGMA_ONCE
0022 #pragma once
0023 #endif
0024
0025 #if defined(BOOST_LOG_NO_THREADS)
0026 #error Boost.Log: This header content is only supported in multithreaded environment
0027 #endif
0028
0029 #include <boost/memory_order.hpp>
0030 #include <boost/atomic/atomic.hpp>
0031 #include <boost/log/detail/event.hpp>
0032 #include <boost/log/detail/threadsafe_queue.hpp>
0033 #include <boost/log/core/record_view.hpp>
0034 #include <boost/log/detail/header.hpp>
0035
0036 namespace boost {
0037
0038 BOOST_LOG_OPEN_NAMESPACE
0039
0040 namespace sinks {
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056 class unbounded_fifo_queue
0057 {
0058 private:
0059 typedef boost::log::aux::threadsafe_queue< record_view > queue_type;
0060
0061 private:
0062
0063 queue_type m_queue;
0064
0065 boost::log::aux::event m_event;
0066
0067 boost::atomic< bool > m_interruption_requested;
0068
0069 protected:
0070
0071 unbounded_fifo_queue() : m_interruption_requested(false)
0072 {
0073 }
0074
0075 template< typename ArgsT >
0076 explicit unbounded_fifo_queue(ArgsT const&) : m_interruption_requested(false)
0077 {
0078 }
0079
0080
0081 void enqueue(record_view const& rec)
0082 {
0083 m_queue.push(rec);
0084 m_event.set_signalled();
0085 }
0086
0087
0088 bool try_enqueue(record_view const& rec)
0089 {
0090
0091 enqueue(rec);
0092 return true;
0093 }
0094
0095
0096 bool try_dequeue_ready(record_view& rec)
0097 {
0098 return m_queue.try_pop(rec);
0099 }
0100
0101
0102 bool try_dequeue(record_view& rec)
0103 {
0104 return m_queue.try_pop(rec);
0105 }
0106
0107
0108 bool dequeue_ready(record_view& rec)
0109 {
0110
0111 if (m_queue.try_pop(rec))
0112 return true;
0113
0114
0115 while (true)
0116 {
0117 m_event.wait();
0118 if (m_interruption_requested.exchange(false, boost::memory_order_acquire))
0119 return false;
0120 if (m_queue.try_pop(rec))
0121 return true;
0122 }
0123 }
0124
0125
0126 void interrupt_dequeue()
0127 {
0128 m_interruption_requested.store(true, boost::memory_order_release);
0129 m_event.set_signalled();
0130 }
0131 };
0132
0133 }
0134
0135 BOOST_LOG_CLOSE_NAMESPACE
0136
0137 }
0138
0139 #include <boost/log/detail/footer.hpp>
0140
0141 #endif