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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. //
  2. // detail/impl/win_mutex.ipp
  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_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. ::InitializeCriticalSectionEx(&crit_section_, 0x80000000, 0);
  39. # else
  40. if (!::InitializeCriticalSectionAndSpinCount(&crit_section_, 0x80000000))
  41. return ::GetLastError();
  42. # endif
  43. return 0;
  44. #else
  45. __try
  46. {
  47. # if defined(UNDER_CE)
  48. ::InitializeCriticalSection(&crit_section_);
  49. # elif defined(ASIO_WINDOWS_APP)
  50. ::InitializeCriticalSectionEx(&crit_section_, 0x80000000, 0);
  51. # else
  52. if (!::InitializeCriticalSectionAndSpinCount(&crit_section_, 0x80000000))
  53. return ::GetLastError();
  54. # endif
  55. }
  56. __except(GetExceptionCode() == STATUS_NO_MEMORY
  57. ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH)
  58. {
  59. return ERROR_OUTOFMEMORY;
  60. }
  61. return 0;
  62. #endif
  63. }
  64. } // namespace detail
  65. } // namespace asio
  66. #include "asio/detail/pop_options.hpp"
  67. #endif // defined(ASIO_WINDOWS)
  68. #endif // ASIO_DETAIL_IMPL_WIN_MUTEX_IPP