Statistics
| Revision:

root / tmp / org.txm.statsengine.r.core.win32 / res / win32 / library / BH / include / boost / asio / detail / impl / win_mutex.ipp @ 2486

History | View | Annotate | Download (2.1 kB)

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

    
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_ASIO_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

    
28
namespace boost {
29
namespace asio {
30
namespace detail {
31

    
32
win_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

    
40
int 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
# elif defined(BOOST_ASIO_WINDOWS_APP)
48
  ::InitializeCriticalSectionEx(&crit_section_, 0x80000000, 0);
49
# else
50
  if (!::InitializeCriticalSectionAndSpinCount(&crit_section_, 0x80000000))
51
    return ::GetLastError();
52
# endif
53
  return 0;
54
#else
55
  __try
56
  {
57
# if defined(UNDER_CE)
58
    ::InitializeCriticalSection(&crit_section_);
59
# elif defined(BOOST_ASIO_WINDOWS_APP)
60
    if (!::InitializeCriticalSectionEx(&crit_section_, 0, 0))
61
	  return ::GetLastError();
62
# else
63
    if (!::InitializeCriticalSectionAndSpinCount(&crit_section_, 0x80000000))
64
      return ::GetLastError();
65
# endif
66
  }
67
  __except(GetExceptionCode() == STATUS_NO_MEMORY
68
      ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH)
69
  {
70
    return ERROR_OUTOFMEMORY;
71
  }
72

    
73
  return 0;
74
#endif
75
}
76

    
77
} // namespace detail
78
} // namespace asio
79
} // namespace boost
80

    
81
#include <boost/asio/detail/pop_options.hpp>
82

    
83
#endif // defined(BOOST_ASIO_WINDOWS)
84

    
85
#endif // BOOST_ASIO_DETAIL_IMPL_WIN_MUTEX_IPP