Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
1.4KB

  1. //
  2. // detail/std_global.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2015 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_STD_GLOBAL_HPP
  11. #define ASIO_DETAIL_STD_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_STD_CALL_ONCE)
  17. #include <exception>
  18. #include <mutex>
  19. #include "asio/detail/push_options.hpp"
  20. namespace asio {
  21. namespace detail {
  22. template <typename T>
  23. struct std_global_impl
  24. {
  25. // Helper function to perform initialisation.
  26. static void do_init()
  27. {
  28. instance_.ptr_ = new T;
  29. }
  30. // Destructor automatically cleans up the global.
  31. ~std_global_impl()
  32. {
  33. delete ptr_;
  34. }
  35. static std::once_flag init_once_;
  36. static std_global_impl instance_;
  37. T* ptr_;
  38. };
  39. template <typename T>
  40. std::once_flag std_global_impl<T>::init_once_;
  41. template <typename T>
  42. std_global_impl<T> std_global_impl<T>::instance_;
  43. template <typename T>
  44. T& std_global()
  45. {
  46. std::call_once(std_global_impl<T>::init_once_, &std_global_impl<T>::do_init);
  47. return *std_global_impl<T>::instance_.ptr_;
  48. }
  49. } // namespace detail
  50. } // namespace asio
  51. #include "asio/detail/pop_options.hpp"
  52. #endif // defined(ASIO_HAS_STD_CALL_ONCE)
  53. #endif // ASIO_DETAIL_STD_GLOBAL_HPP