File indexing completed on 2025-01-18 09:39:22
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #ifndef BOOST_LOG_DETAIL_THREAD_SPECIFIC_HPP_INCLUDED_
0017 #define BOOST_LOG_DETAIL_THREAD_SPECIFIC_HPP_INCLUDED_
0018
0019 #include <boost/type_traits/is_pod.hpp>
0020 #include <boost/log/detail/config.hpp>
0021
0022 #ifdef BOOST_HAS_PRAGMA_ONCE
0023 #pragma once
0024 #endif
0025
0026 #if !defined(BOOST_LOG_NO_THREADS)
0027
0028 #include <boost/log/detail/header.hpp>
0029
0030 namespace boost {
0031
0032 BOOST_LOG_OPEN_NAMESPACE
0033
0034 namespace aux {
0035
0036
0037 class thread_specific_base
0038 {
0039 private:
0040 #if defined(BOOST_THREAD_PLATFORM_WIN32)
0041 typedef unsigned long key_storage;
0042 #else
0043 typedef void* key_storage;
0044 #endif
0045
0046 key_storage m_Key;
0047
0048 protected:
0049 BOOST_LOG_API thread_specific_base();
0050 BOOST_LOG_API ~thread_specific_base();
0051 BOOST_LOG_API void* get_content() const;
0052 BOOST_LOG_API void set_content(void* value) const;
0053
0054
0055 BOOST_DELETED_FUNCTION(thread_specific_base(thread_specific_base const&))
0056 BOOST_DELETED_FUNCTION(thread_specific_base& operator= (thread_specific_base const&))
0057 };
0058
0059
0060 template< typename T >
0061 class thread_specific :
0062 public thread_specific_base
0063 {
0064 static_assert(sizeof(T) <= sizeof(void*) && is_pod< T >::value, "Boost.Log: Thread-specific values must be PODs and must not exceed the size of a pointer");
0065
0066
0067 union value_storage
0068 {
0069 void* as_pointer;
0070 T as_value;
0071 };
0072
0073 public:
0074
0075 BOOST_DEFAULTED_FUNCTION(thread_specific(), {})
0076
0077 thread_specific(T const& value)
0078 {
0079 set(value);
0080 }
0081
0082 thread_specific& operator= (T const& value)
0083 {
0084 set(value);
0085 return *this;
0086 }
0087
0088
0089 T get() const
0090 {
0091 value_storage cast = {};
0092 cast.as_pointer = thread_specific_base::get_content();
0093 return cast.as_value;
0094 }
0095
0096
0097 void set(T const& value)
0098 {
0099 value_storage cast = {};
0100 cast.as_value = value;
0101 thread_specific_base::set_content(cast.as_pointer);
0102 }
0103 };
0104
0105 }
0106
0107 BOOST_LOG_CLOSE_NAMESPACE
0108
0109 }
0110
0111 #include <boost/log/detail/footer.hpp>
0112
0113 #endif
0114
0115 #endif