File indexing completed on 2025-01-30 09:33:18
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_ASIO_DETAIL_WIN_GLOBAL_HPP
0012 #define BOOST_ASIO_DETAIL_WIN_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 <boost/asio/detail/static_mutex.hpp>
0020 #include <boost/asio/detail/tss_ptr.hpp>
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 win_global_impl
0030 {
0031
0032 ~win_global_impl()
0033 {
0034 delete ptr_;
0035 }
0036
0037 static win_global_impl instance_;
0038 static static_mutex mutex_;
0039 T* ptr_;
0040 static tss_ptr<T> tss_ptr_;
0041 };
0042
0043 template <typename T>
0044 win_global_impl<T> win_global_impl<T>::instance_ = { 0 };
0045
0046 template <typename T>
0047 static_mutex win_global_impl<T>::mutex_ = BOOST_ASIO_STATIC_MUTEX_INIT;
0048
0049 template <typename T>
0050 tss_ptr<T> win_global_impl<T>::tss_ptr_;
0051
0052 template <typename T>
0053 T& win_global()
0054 {
0055 if (static_cast<T*>(win_global_impl<T>::tss_ptr_) == 0)
0056 {
0057 win_global_impl<T>::mutex_.init();
0058 static_mutex::scoped_lock lock(win_global_impl<T>::mutex_);
0059 if (win_global_impl<T>::instance_.ptr_ == 0)
0060 win_global_impl<T>::instance_.ptr_ = new T;
0061 win_global_impl<T>::tss_ptr_ = win_global_impl<T>::instance_.ptr_;
0062 }
0063
0064 return *win_global_impl<T>::tss_ptr_;
0065 }
0066
0067 }
0068 }
0069 }
0070
0071 #include <boost/asio/detail/pop_options.hpp>
0072
0073 #endif