5
// Copyright (c) 2003-2008 Christopher M. Kohlhoff (chris at kohlhoff dot com)
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)
11
#ifndef ASIO_DETAIL_WIN_MUTEX_HPP
12
#define ASIO_DETAIL_WIN_MUTEX_HPP
14
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
16
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18
#include "asio/detail/push_options.hpp"
20
#include "asio/detail/push_options.hpp"
21
#include <boost/config.hpp>
22
#include "asio/detail/pop_options.hpp"
24
#if defined(BOOST_WINDOWS)
26
#include "asio/error.hpp"
27
#include "asio/system_error.hpp"
28
#include "asio/detail/noncopyable.hpp"
29
#include "asio/detail/socket_types.hpp"
30
#include "asio/detail/scoped_lock.hpp"
32
#include "asio/detail/push_options.hpp"
33
#include <boost/throw_exception.hpp>
34
#include "asio/detail/pop_options.hpp"
43
typedef asio::detail::scoped_lock<win_mutex> scoped_lock;
48
int error = do_init();
52
asio::error_code(error,
53
asio::error::get_system_category()),
55
boost::throw_exception(e);
62
::DeleteCriticalSection(&crit_section_);
68
int error = do_lock();
72
asio::error_code(error,
73
asio::error::get_system_category()),
75
boost::throw_exception(e);
82
::LeaveCriticalSection(&crit_section_);
86
// Initialisation must be performed in a separate function to the constructor
87
// since the compiler does not support the use of structured exceptions and
88
// C++ exceptions in the same function.
91
#if defined(__MINGW32__)
92
// Not sure if MinGW supports structured exception handling, so for now
93
// we'll just call the Windows API and hope.
94
::InitializeCriticalSection(&crit_section_);
99
::InitializeCriticalSection(&crit_section_);
101
__except(GetExceptionCode() == STATUS_NO_MEMORY
102
? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH)
104
return ERROR_OUTOFMEMORY;
111
// Locking must be performed in a separate function to lock() since the
112
// compiler does not support the use of structured exceptions and C++
113
// exceptions in the same function.
116
#if defined(__MINGW32__)
117
// Not sure if MinGW supports structured exception handling, so for now
118
// we'll just call the Windows API and hope.
119
::EnterCriticalSection(&crit_section_);
124
::EnterCriticalSection(&crit_section_);
126
__except(GetExceptionCode() == STATUS_INVALID_HANDLE
127
|| GetExceptionCode() == STATUS_NO_MEMORY
128
? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH)
130
if (GetExceptionCode() == STATUS_NO_MEMORY)
131
return ERROR_OUTOFMEMORY;
132
return ERROR_INVALID_HANDLE;
139
::CRITICAL_SECTION crit_section_;
142
} // namespace detail
145
#endif // defined(BOOST_WINDOWS)
147
#include "asio/detail/pop_options.hpp"
149
#endif // ASIO_DETAIL_WIN_MUTEX_HPP