PageRenderTime 20ms CodeModel.GetById 16ms app.highlight 1ms RepoModel.GetById 2ms app.codeStats 0ms

/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
11#ifndef BOOST_ASIO_DETAIL_IMPL_WIN_MUTEX_IPP
12#define BOOST_ASIO_DETAIL_IMPL_WIN_MUTEX_IPP
13
14#if defined(_MSC_VER) && (_MSC_VER >= 1200)
15# pragma once
16#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17
18#include <boost/asio/detail/config.hpp>
19
20#if defined(BOOST_WINDOWS)
21
22#include <boost/asio/detail/throw_error.hpp>
23#include <boost/asio/detail/win_mutex.hpp>
24#include <boost/asio/error.hpp>
25
26#include <boost/asio/detail/push_options.hpp>
27
28namespace boost {
29namespace asio {
30namespace detail {
31
32win_mutex::win_mutex()
33{
34  int error = do_init();
35  boost::system::error_code ec(error,
36      boost::asio::error::get_system_category());
37  boost::asio::detail::throw_error(ec, "mutex");
38}
39
40int win_mutex::do_init()
41{
42#if defined(__MINGW32__)
43  // Not sure if MinGW supports structured exception handling, so for now
44  // we'll just call the Windows API and hope.
45# if defined(UNDER_CE)
46  ::InitializeCriticalSection(&crit_section_);
47# else
48  if (!::InitializeCriticalSectionAndSpinCount(&crit_section_, 0x80000000))
49    return ::GetLastError();
50# endif
51  return 0;
52#else
53  __try
54  {
55# if defined(UNDER_CE)
56    ::InitializeCriticalSection(&crit_section_);
57# else
58    if (!::InitializeCriticalSectionAndSpinCount(&crit_section_, 0x80000000))
59      return ::GetLastError();
60# endif
61  }
62  __except(GetExceptionCode() == STATUS_NO_MEMORY
63      ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH)
64  {
65    return ERROR_OUTOFMEMORY;
66  }
67
68  return 0;
69#endif
70}
71
72} // namespace detail
73} // namespace asio
74} // namespace boost
75
76#include <boost/asio/detail/pop_options.hpp>
77
78#endif // defined(BOOST_WINDOWS)
79
80#endif // BOOST_ASIO_DETAIL_IMPL_WIN_MUTEX_IPP