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_mutex.ipp 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. //
  2. // detail/impl/win_mutex.ipp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2019 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_MUTEX_IPP
  11. #define ASIO_DETAIL_IMPL_WIN_MUTEX_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_mutex.hpp"
  19. #include "asio/error.hpp"
  20. #include "asio/detail/push_options.hpp"
  21. namespace asio {
  22. namespace detail {
  23. win_mutex::win_mutex()
  24. {
  25. int error = do_init();
  26. asio::error_code ec(error,
  27. asio::error::get_system_category());
  28. asio::detail::throw_error(ec, "mutex");
  29. }
  30. int win_mutex::do_init()
  31. {
  32. #if defined(__MINGW32__)
  33. // Not sure if MinGW supports structured exception handling, so for now
  34. // we'll just call the Windows API and hope.
  35. # if defined(UNDER_CE)
  36. ::InitializeCriticalSection(&crit_section_);
  37. # elif defined(ASIO_WINDOWS_APP)
  38. if (!::InitializeCriticalSectionEx(&crit_section_, 0, 0))
  39. return ::GetLastError();
  40. # else
  41. if (!::InitializeCriticalSectionAndSpinCount(&crit_section_, 0x80000000))
  42. return ::GetLastError();
  43. # endif
  44. return 0;
  45. #else
  46. __try
  47. {
  48. # if defined(UNDER_CE)
  49. ::InitializeCriticalSection(&crit_section_);
  50. # elif defined(ASIO_WINDOWS_APP)
  51. if (!::InitializeCriticalSectionEx(&crit_section_, 0, 0))
  52. return ::GetLastError();
  53. # else
  54. if (!::InitializeCriticalSectionAndSpinCount(&crit_section_, 0x80000000))
  55. return ::GetLastError();
  56. # endif
  57. }
  58. __except(GetExceptionCode() == STATUS_NO_MEMORY
  59. ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH)
  60. {
  61. return ERROR_OUTOFMEMORY;
  62. }
  63. return 0;
  64. #endif
  65. }
  66. } // namespace detail
  67. } // namespace asio
  68. #include "asio/detail/pop_options.hpp"
  69. #endif // defined(ASIO_WINDOWS)
  70. #endif // ASIO_DETAIL_IMPL_WIN_MUTEX_IPP