File indexing completed on 2025-01-18 09:39:18
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef BOOST_LOG_ATTRIBUTES_CURRENT_THREAD_ID_HPP_INCLUDED_
0016 #define BOOST_LOG_ATTRIBUTES_CURRENT_THREAD_ID_HPP_INCLUDED_
0017
0018 #include <boost/log/detail/config.hpp>
0019
0020 #ifdef BOOST_HAS_PRAGMA_ONCE
0021 #pragma once
0022 #endif
0023
0024 #if defined(BOOST_LOG_NO_THREADS)
0025 #error Boost.Log: The current_thread_id attribute is only available in multithreaded builds
0026 #endif
0027
0028 #include <boost/smart_ptr/intrusive_ptr.hpp>
0029 #include <boost/log/detail/thread_id.hpp>
0030 #include <boost/log/attributes/attribute.hpp>
0031 #include <boost/log/attributes/attribute_cast.hpp>
0032 #include <boost/log/attributes/attribute_value_impl.hpp>
0033 #include <boost/log/detail/header.hpp>
0034
0035 namespace boost {
0036
0037 BOOST_LOG_OPEN_NAMESPACE
0038
0039
0040 typedef boost::log::aux::thread::id thread_id;
0041
0042 namespace attributes {
0043
0044
0045
0046
0047
0048
0049
0050 class current_thread_id :
0051 public attribute
0052 {
0053 public:
0054
0055 typedef thread_id value_type;
0056
0057 protected:
0058
0059 class BOOST_SYMBOL_VISIBLE impl :
0060 public attribute_value::impl
0061 {
0062 public:
0063 bool dispatch(type_dispatcher& dispatcher)
0064 {
0065 type_dispatcher::callback< value_type > callback =
0066 dispatcher.get_callback< value_type >();
0067 if (callback)
0068 {
0069 callback(boost::log::aux::this_thread::get_id());
0070 return true;
0071 }
0072 else
0073 return false;
0074 }
0075
0076 intrusive_ptr< attribute_value::impl > detach_from_thread()
0077 {
0078 typedef attribute_value_impl< value_type > detached_value;
0079 return new detached_value(boost::log::aux::this_thread::get_id());
0080 }
0081
0082 typeindex::type_index get_type() const { return typeindex::type_id< value_type >(); }
0083 };
0084
0085 public:
0086
0087
0088
0089 current_thread_id() : attribute(new impl())
0090 {
0091 }
0092
0093
0094
0095 explicit current_thread_id(cast_source const& source) :
0096 attribute(source.as< impl >())
0097 {
0098 }
0099 };
0100
0101 }
0102
0103 BOOST_LOG_CLOSE_NAMESPACE
0104
0105 }
0106
0107 #include <boost/log/detail/footer.hpp>
0108
0109 #endif