win_tss_ptr.ipp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. //
  2. // detail/impl/win_tss_ptr.ipp
  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_IMPL_WIN_TSS_PTR_IPP
  11. #define ASIO_DETAIL_IMPL_WIN_TSS_PTR_IPP
  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/throw_error.hpp"
  18. #include "asio/detail/win_tss_ptr.hpp"
  19. #include "asio/error.hpp"
  20. #include "asio/detail/push_options.hpp"
  21. namespace asio {
  22. namespace detail {
  23. DWORD win_tss_ptr_create()
  24. {
  25. #if defined(UNDER_CE)
  26. const DWORD out_of_indexes = 0xFFFFFFFF;
  27. #else
  28. const DWORD out_of_indexes = TLS_OUT_OF_INDEXES;
  29. #endif
  30. DWORD tss_key = ::TlsAlloc();
  31. if (tss_key == out_of_indexes)
  32. {
  33. DWORD last_error = ::GetLastError();
  34. asio::error_code ec(last_error,
  35. asio::error::get_system_category());
  36. asio::detail::throw_error(ec, "tss");
  37. }
  38. return tss_key;
  39. }
  40. } // namespace detail
  41. } // namespace asio
  42. #include "asio/detail/pop_options.hpp"
  43. #endif // defined(ASIO_WINDOWS)
  44. #endif // ASIO_DETAIL_IMPL_WIN_TSS_PTR_IPP