]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // |
2 | // detail/win_mutex.hpp | |
3 | // ~~~~~~~~~~~~~~~~~~~~ | |
4 | // | |
5 | // Copyright (c) 2003-2016 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_WIN_MUTEX_HPP | |
12 | #define BOOST_ASIO_DETAIL_WIN_MUTEX_HPP | |
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/noncopyable.hpp> | |
23 | #include <boost/asio/detail/scoped_lock.hpp> | |
24 | #include <boost/asio/detail/socket_types.hpp> | |
25 | ||
26 | #include <boost/asio/detail/push_options.hpp> | |
27 | ||
28 | namespace boost { | |
29 | namespace asio { | |
30 | namespace detail { | |
31 | ||
32 | class win_mutex | |
33 | : private noncopyable | |
34 | { | |
35 | public: | |
36 | typedef boost::asio::detail::scoped_lock<win_mutex> scoped_lock; | |
37 | ||
38 | // Constructor. | |
39 | BOOST_ASIO_DECL win_mutex(); | |
40 | ||
41 | // Destructor. | |
42 | ~win_mutex() | |
43 | { | |
44 | ::DeleteCriticalSection(&crit_section_); | |
45 | } | |
46 | ||
47 | // Lock the mutex. | |
48 | void lock() | |
49 | { | |
50 | ::EnterCriticalSection(&crit_section_); | |
51 | } | |
52 | ||
53 | // Unlock the mutex. | |
54 | void unlock() | |
55 | { | |
56 | ::LeaveCriticalSection(&crit_section_); | |
57 | } | |
58 | ||
59 | private: | |
60 | // Initialisation must be performed in a separate function to the constructor | |
61 | // since the compiler does not support the use of structured exceptions and | |
62 | // C++ exceptions in the same function. | |
63 | BOOST_ASIO_DECL int do_init(); | |
64 | ||
65 | ::CRITICAL_SECTION crit_section_; | |
66 | }; | |
67 | ||
68 | } // namespace detail | |
69 | } // namespace asio | |
70 | } // namespace boost | |
71 | ||
72 | #include <boost/asio/detail/pop_options.hpp> | |
73 | ||
74 | #if defined(BOOST_ASIO_HEADER_ONLY) | |
75 | # include <boost/asio/detail/impl/win_mutex.ipp> | |
76 | #endif // defined(BOOST_ASIO_HEADER_ONLY) | |
77 | ||
78 | #endif // defined(BOOST_ASIO_WINDOWS) | |
79 | ||
80 | #endif // BOOST_ASIO_DETAIL_WIN_MUTEX_HPP |