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_BLOCK_ON_OVERFLOW_HPP_INCLUDED_
0017 #define BOOST_LOG_SINKS_BLOCK_ON_OVERFLOW_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/intrusive/options.hpp>
0030 #include <boost/intrusive/list.hpp>
0031 #include <boost/intrusive/list_hook.hpp>
0032 #include <boost/thread/condition_variable.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 class block_on_overflow
0051 {
0052 #ifndef BOOST_LOG_DOXYGEN_PASS
0053 private:
0054 typedef intrusive::list_base_hook<
0055 intrusive::link_mode< intrusive::auto_unlink >
0056 > thread_context_hook_t;
0057
0058 struct thread_context :
0059 public thread_context_hook_t
0060 {
0061 condition_variable cond;
0062 bool result;
0063
0064 thread_context() : result(true) {}
0065 };
0066
0067 typedef intrusive::list<
0068 thread_context,
0069 intrusive::base_hook< thread_context_hook_t >,
0070 intrusive::constant_time_size< false >
0071 > thread_contexts;
0072
0073 private:
0074
0075 thread_contexts m_thread_contexts;
0076
0077 public:
0078
0079
0080
0081 BOOST_DEFAULTED_FUNCTION(block_on_overflow(), {})
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091 template< typename LockT >
0092 bool on_overflow(record_view const&, LockT& lock)
0093 {
0094 thread_context context;
0095 m_thread_contexts.push_back(context);
0096 do
0097 {
0098 context.cond.wait(lock);
0099 }
0100 while (context.is_linked());
0101
0102 return context.result;
0103 }
0104
0105
0106
0107
0108
0109 void on_queue_space_available()
0110 {
0111 if (!m_thread_contexts.empty())
0112 {
0113 m_thread_contexts.front().cond.notify_one();
0114 m_thread_contexts.pop_front();
0115 }
0116 }
0117
0118
0119
0120
0121
0122 void interrupt()
0123 {
0124 while (!m_thread_contexts.empty())
0125 {
0126 thread_context& context = m_thread_contexts.front();
0127 context.result = false;
0128 context.cond.notify_one();
0129 m_thread_contexts.pop_front();
0130 }
0131 }
0132
0133
0134 BOOST_DELETED_FUNCTION(block_on_overflow(block_on_overflow const&))
0135 BOOST_DELETED_FUNCTION(block_on_overflow& operator= (block_on_overflow const&))
0136 #endif
0137 };
0138
0139 }
0140
0141 BOOST_LOG_CLOSE_NAMESPACE
0142
0143 }
0144
0145 #include <boost/log/detail/footer.hpp>
0146
0147 #endif