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_tss_ptr.hpp 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. //
  2. // detail/win_tss_ptr.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_TSS_PTR_HPP
  11. #define ASIO_DETAIL_WIN_TSS_PTR_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_WINDOWS)
  17. #include "asio/detail/noncopyable.hpp"
  18. #include "asio/detail/socket_types.hpp"
  19. #include "asio/detail/push_options.hpp"
  20. namespace asio {
  21. namespace detail {
  22. // Helper function to create thread-specific storage.
  23. ASIO_DECL DWORD win_tss_ptr_create();
  24. template <typename T>
  25. class win_tss_ptr
  26. : private noncopyable
  27. {
  28. public:
  29. // Constructor.
  30. win_tss_ptr()
  31. : tss_key_(win_tss_ptr_create())
  32. {
  33. }
  34. // Destructor.
  35. ~win_tss_ptr()
  36. {
  37. ::TlsFree(tss_key_);
  38. }
  39. // Get the value.
  40. operator T*() const
  41. {
  42. return static_cast<T*>(::TlsGetValue(tss_key_));
  43. }
  44. // Set the value.
  45. void operator=(T* value)
  46. {
  47. ::TlsSetValue(tss_key_, value);
  48. }
  49. private:
  50. // Thread-specific storage to allow unlocked access to determine whether a
  51. // thread is a member of the pool.
  52. DWORD tss_key_;
  53. };
  54. } // namespace detail
  55. } // namespace asio
  56. #include "asio/detail/pop_options.hpp"
  57. #if defined(ASIO_HEADER_ONLY)
  58. # include "asio/detail/impl/win_tss_ptr.ipp"
  59. #endif // defined(ASIO_HEADER_ONLY)
  60. #endif // defined(ASIO_WINDOWS)
  61. #endif // ASIO_DETAIL_WIN_TSS_PTR_HPP