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.

win_global.hpp 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. //
  2. // detail/win_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_WIN_GLOBAL_HPP
  11. #define ASIO_DETAIL_WIN_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. #include "asio/detail/static_mutex.hpp"
  17. #include "asio/detail/tss_ptr.hpp"
  18. #include "asio/detail/push_options.hpp"
  19. namespace asio {
  20. namespace detail {
  21. template <typename T>
  22. struct win_global_impl
  23. {
  24. // Destructor automatically cleans up the global.
  25. ~win_global_impl()
  26. {
  27. delete ptr_;
  28. }
  29. static win_global_impl instance_;
  30. static static_mutex mutex_;
  31. static T* ptr_;
  32. static tss_ptr<T> tss_ptr_;
  33. };
  34. template <typename T>
  35. win_global_impl<T> win_global_impl<T>::instance_ = { 0 };
  36. template <typename T>
  37. static_mutex win_global_impl<T>::mutex_ = ASIO_STATIC_MUTEX_INIT;
  38. template <typename T>
  39. T* win_global_impl<T>::ptr_ = 0;
  40. template <typename T>
  41. tss_ptr<T> win_global_impl<T>::tss_ptr_;
  42. template <typename T>
  43. T& win_global()
  44. {
  45. if (static_cast<T*>(win_global_impl<T>::tss_ptr_) == 0)
  46. {
  47. win_global_impl<T>::mutex_.init();
  48. static_mutex::scoped_lock lock(win_global_impl<T>::mutex_);
  49. win_global_impl<T>::ptr_ = new T;
  50. win_global_impl<T>::tss_ptr_ = win_global_impl<T>::ptr_;
  51. }
  52. return *win_global_impl<T>::tss_ptr_;
  53. }
  54. } // namespace detail
  55. } // namespace asio
  56. #include "asio/detail/pop_options.hpp"
  57. #endif // ASIO_DETAIL_WIN_GLOBAL_HPP