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.

posix_tss_ptr.hpp 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. //
  2. // detail/posix_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_POSIX_TSS_PTR_HPP
  11. #define ASIO_DETAIL_POSIX_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_HAS_PTHREADS)
  17. #include <pthread.h>
  18. #include "asio/detail/noncopyable.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 void posix_tss_ptr_create(pthread_key_t& key);
  24. template <typename T>
  25. class posix_tss_ptr
  26. : private noncopyable
  27. {
  28. public:
  29. // Constructor.
  30. posix_tss_ptr()
  31. {
  32. posix_tss_ptr_create(tss_key_);
  33. }
  34. // Destructor.
  35. ~posix_tss_ptr()
  36. {
  37. ::pthread_key_delete(tss_key_);
  38. }
  39. // Get the value.
  40. operator T*() const
  41. {
  42. return static_cast<T*>(::pthread_getspecific(tss_key_));
  43. }
  44. // Set the value.
  45. void operator=(T* value)
  46. {
  47. ::pthread_setspecific(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. pthread_key_t 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/posix_tss_ptr.ipp"
  59. #endif // defined(ASIO_HEADER_ONLY)
  60. #endif // defined(ASIO_HAS_PTHREADS)
  61. #endif // ASIO_DETAIL_POSIX_TSS_PTR_HPP