File indexing completed on 2025-01-18 09:28:45
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_ASIO_DETAIL_STD_GLOBAL_HPP
0012 #define BOOST_ASIO_DETAIL_STD_GLOBAL_HPP
0013
0014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0015 # pragma once
0016 #endif
0017
0018 #include <boost/asio/detail/config.hpp>
0019 #include <exception>
0020 #include <mutex>
0021
0022 #include <boost/asio/detail/push_options.hpp>
0023
0024 namespace boost {
0025 namespace asio {
0026 namespace detail {
0027
0028 template <typename T>
0029 struct std_global_impl
0030 {
0031
0032 static void do_init()
0033 {
0034 instance_.ptr_ = new T;
0035 }
0036
0037
0038 ~std_global_impl()
0039 {
0040 delete ptr_;
0041 }
0042
0043 static std::once_flag init_once_;
0044 static std_global_impl instance_;
0045 T* ptr_;
0046 };
0047
0048 template <typename T>
0049 std::once_flag std_global_impl<T>::init_once_;
0050
0051 template <typename T>
0052 std_global_impl<T> std_global_impl<T>::instance_;
0053
0054 template <typename T>
0055 T& std_global()
0056 {
0057 std::call_once(std_global_impl<T>::init_once_, &std_global_impl<T>::do_init);
0058 return *std_global_impl<T>::instance_.ptr_;
0059 }
0060
0061 }
0062 }
0063 }
0064
0065 #include <boost/asio/detail/pop_options.hpp>
0066
0067 #endif