global.hpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. //
  2. // detail/global.hpp
  3. // ~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2023 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 ASIO_DETAIL_GLOBAL_HPP
  11. #define 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 "asio/detail/config.hpp"
  16. #if !defined(ASIO_HAS_THREADS)
  17. # include "asio/detail/null_global.hpp"
  18. #elif defined(ASIO_WINDOWS)
  19. # include "asio/detail/win_global.hpp"
  20. #elif defined(ASIO_HAS_PTHREADS)
  21. # include "asio/detail/posix_global.hpp"
  22. #else
  23. # include "asio/detail/std_global.hpp"
  24. #endif
  25. namespace asio {
  26. namespace detail {
  27. template <typename T>
  28. inline T& global()
  29. {
  30. #if !defined(ASIO_HAS_THREADS)
  31. return null_global<T>();
  32. #elif defined(ASIO_WINDOWS)
  33. return win_global<T>();
  34. #elif defined(ASIO_HAS_PTHREADS)
  35. return posix_global<T>();
  36. #else
  37. return std_global<T>();
  38. #endif
  39. }
  40. } // namespace detail
  41. } // namespace asio
  42. #endif // ASIO_DETAIL_GLOBAL_HPP