2 // detail/win_global.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~
5 // Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com)
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
11 #ifndef BOOST_ASIO_DETAIL_WIN_GLOBAL_HPP
12 #define BOOST_ASIO_DETAIL_WIN_GLOBAL_HPP
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18 #include <boost/asio/detail/config.hpp>
19 #include <boost/asio/detail/static_mutex.hpp>
20 #include <boost/asio/detail/tss_ptr.hpp>
22 #include <boost/asio/detail/push_options.hpp>
29 struct win_global_impl
31 // Destructor automatically cleans up the global.
37 static win_global_impl instance_;
38 static static_mutex mutex_;
40 static tss_ptr<T> tss_ptr_;
44 win_global_impl<T> win_global_impl<T>::instance_ = { 0 };
47 static_mutex win_global_impl<T>::mutex_ = BOOST_ASIO_STATIC_MUTEX_INIT;
50 T* win_global_impl<T>::ptr_ = 0;
53 tss_ptr<T> win_global_impl<T>::tss_ptr_;
58 if (static_cast<T*>(win_global_impl<T>::tss_ptr_) == 0)
60 win_global_impl<T>::mutex_.init();
61 static_mutex::scoped_lock lock(win_global_impl<T>::mutex_);
62 win_global_impl<T>::ptr_ = new T;
63 win_global_impl<T>::tss_ptr_ = win_global_impl<T>::ptr_;
66 return *win_global_impl<T>::tss_ptr_;
73 #include <boost/asio/detail/pop_options.hpp>
75 #endif // BOOST_ASIO_DETAIL_WIN_GLOBAL_HPP