/Src/Dependencies/Boost/boost/asio/detail/impl/win_mutex.ipp

http://hadesmem.googlecode.com/ · C++ Header · 80 lines · 55 code · 14 blank · 11 comment · 6 complexity · dbd7f19a6301c5e1ce64be7be9c4efd5 MD5 · raw file

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