Chris@16
|
1 //
|
Chris@16
|
2 // detail/win_static_mutex.hpp
|
Chris@16
|
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
Chris@16
|
4 //
|
Chris@101
|
5 // Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
Chris@16
|
6 //
|
Chris@16
|
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
|
Chris@16
|
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
9 //
|
Chris@16
|
10
|
Chris@16
|
11 #ifndef BOOST_ASIO_DETAIL_WIN_STATIC_MUTEX_HPP
|
Chris@16
|
12 #define BOOST_ASIO_DETAIL_WIN_STATIC_MUTEX_HPP
|
Chris@16
|
13
|
Chris@16
|
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
Chris@16
|
15 # pragma once
|
Chris@16
|
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
Chris@16
|
17
|
Chris@16
|
18 #include <boost/asio/detail/config.hpp>
|
Chris@16
|
19
|
Chris@16
|
20 #if defined(BOOST_ASIO_WINDOWS)
|
Chris@16
|
21
|
Chris@16
|
22 #include <boost/asio/detail/scoped_lock.hpp>
|
Chris@16
|
23
|
Chris@16
|
24 #include <boost/asio/detail/push_options.hpp>
|
Chris@16
|
25
|
Chris@16
|
26 namespace boost {
|
Chris@16
|
27 namespace asio {
|
Chris@16
|
28 namespace detail {
|
Chris@16
|
29
|
Chris@16
|
30 struct win_static_mutex
|
Chris@16
|
31 {
|
Chris@16
|
32 typedef boost::asio::detail::scoped_lock<win_static_mutex> scoped_lock;
|
Chris@16
|
33
|
Chris@16
|
34 // Initialise the mutex.
|
Chris@16
|
35 BOOST_ASIO_DECL void init();
|
Chris@16
|
36
|
Chris@16
|
37 // Initialisation must be performed in a separate function to the "public"
|
Chris@16
|
38 // init() function since the compiler does not support the use of structured
|
Chris@16
|
39 // exceptions and C++ exceptions in the same function.
|
Chris@16
|
40 BOOST_ASIO_DECL int do_init();
|
Chris@16
|
41
|
Chris@16
|
42 // Lock the mutex.
|
Chris@16
|
43 void lock()
|
Chris@16
|
44 {
|
Chris@16
|
45 ::EnterCriticalSection(&crit_section_);
|
Chris@16
|
46 }
|
Chris@16
|
47
|
Chris@16
|
48 // Unlock the mutex.
|
Chris@16
|
49 void unlock()
|
Chris@16
|
50 {
|
Chris@16
|
51 ::LeaveCriticalSection(&crit_section_);
|
Chris@16
|
52 }
|
Chris@16
|
53
|
Chris@16
|
54 bool initialised_;
|
Chris@16
|
55 ::CRITICAL_SECTION crit_section_;
|
Chris@16
|
56 };
|
Chris@16
|
57
|
Chris@16
|
58 #if defined(UNDER_CE)
|
Chris@16
|
59 # define BOOST_ASIO_WIN_STATIC_MUTEX_INIT { false, { 0, 0, 0, 0, 0 } }
|
Chris@16
|
60 #else // defined(UNDER_CE)
|
Chris@16
|
61 # define BOOST_ASIO_WIN_STATIC_MUTEX_INIT { false, { 0, 0, 0, 0, 0, 0 } }
|
Chris@16
|
62 #endif // defined(UNDER_CE)
|
Chris@16
|
63
|
Chris@16
|
64 } // namespace detail
|
Chris@16
|
65 } // namespace asio
|
Chris@16
|
66 } // namespace boost
|
Chris@16
|
67
|
Chris@16
|
68 #include <boost/asio/detail/pop_options.hpp>
|
Chris@16
|
69
|
Chris@16
|
70 #if defined(BOOST_ASIO_HEADER_ONLY)
|
Chris@16
|
71 # include <boost/asio/detail/impl/win_static_mutex.ipp>
|
Chris@16
|
72 #endif // defined(BOOST_ASIO_HEADER_ONLY)
|
Chris@16
|
73
|
Chris@16
|
74 #endif // defined(BOOST_ASIO_WINDOWS)
|
Chris@16
|
75
|
Chris@16
|
76 #endif // BOOST_ASIO_DETAIL_WIN_STATIC_MUTEX_HPP
|