1 // 2 // detail/global.hpp 3 // ~~~~~~~~~~~~~~~~~ 4 // 5 // Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com) 6 // 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) 9 // 10 11 #ifndef ASIO_DETAIL_GLOBAL_HPP 12 #define ASIO_DETAIL_GLOBAL_HPP 13 14 #if defined(_MSC_VER) && (_MSC_VER >= 1200) 15 # pragma once 16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) 17 18 #include "asio/detail/config.hpp" 19 20 #if !defined(ASIO_HAS_THREADS) 21 # include "asio/detail/null_global.hpp" 22 #elif defined(ASIO_WINDOWS) 23 # include "asio/detail/win_global.hpp" 24 #elif defined(ASIO_HAS_PTHREADS) 25 # include "asio/detail/posix_global.hpp" 26 #elif defined(ASIO_HAS_STD_CALL_ONCE) 27 # include "asio/detail/std_global.hpp" 28 #else 29 # error Only Windows, POSIX and std::call_once are supported! 30 #endif 31 32 namespace asio { 33 namespace detail { 34 35 template <typename T> global()36inline T& global() 37 { 38 #if !defined(ASIO_HAS_THREADS) 39 return null_global<T>(); 40 #elif defined(ASIO_WINDOWS) 41 return win_global<T>(); 42 #elif defined(ASIO_HAS_PTHREADS) 43 return posix_global<T>(); 44 #elif defined(ASIO_HAS_STD_CALL_ONCE) 45 return std_global<T>(); 46 #endif 47 } 48 49 } // namespace detail 50 } // namespace asio 51 52 #endif // ASIO_DETAIL_GLOBAL_HPP 53