global.hpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. //
  2. // detail/global.hpp
  3. // ~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2021 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. #ifndef BOOST_ASIO_DETAIL_GLOBAL_HPP
  11. #define BOOST_ASIO_DETAIL_GLOBAL_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include <boost/asio/detail/config.hpp>
  16. #if !defined(BOOST_ASIO_HAS_THREADS)
  17. # include <boost/asio/detail/null_global.hpp>
  18. #elif defined(BOOST_ASIO_WINDOWS)
  19. # include <boost/asio/detail/win_global.hpp>
  20. #elif defined(BOOST_ASIO_HAS_PTHREADS)
  21. # include <boost/asio/detail/posix_global.hpp>
  22. #elif defined(BOOST_ASIO_HAS_STD_CALL_ONCE)
  23. # include <boost/asio/detail/std_global.hpp>
  24. #else
  25. # error Only Windows, POSIX and std::call_once are supported!
  26. #endif
  27. namespace boost {
  28. namespace asio {
  29. namespace detail {
  30. template <typename T>
  31. inline T& global()
  32. {
  33. #if !defined(BOOST_ASIO_HAS_THREADS)
  34. return null_global<T>();
  35. #elif defined(BOOST_ASIO_WINDOWS)
  36. return win_global<T>();
  37. #elif defined(BOOST_ASIO_HAS_PTHREADS)
  38. return posix_global<T>();
  39. #elif defined(BOOST_ASIO_HAS_STD_CALL_ONCE)
  40. return std_global<T>();
  41. #endif
  42. }
  43. } // namespace detail
  44. } // namespace asio
  45. } // namespace boost
  46. #endif // BOOST_ASIO_DETAIL_GLOBAL_HPP