1 // 2 // detail/win_static_mutex.hpp 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_WIN_STATIC_MUTEX_HPP 12 #define BOOST_ASIO_DETAIL_WIN_STATIC_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/scoped_lock.hpp> 23 24 #include <boost/asio/detail/push_options.hpp> 25 26 namespace boost { 27 namespace asio { 28 namespace detail { 29 30 struct win_static_mutex 31 { 32 typedef boost::asio::detail::scoped_lock<win_static_mutex> scoped_lock; 33 34 // Initialise the mutex. 35 BOOST_ASIO_DECL void init(); 36 37 // Initialisation must be performed in a separate function to the "public" 38 // init() function since the compiler does not support the use of structured 39 // exceptions and C++ exceptions in the same function. 40 BOOST_ASIO_DECL int do_init(); 41 42 // Lock the mutex. lockboost::asio::detail::win_static_mutex43 void lock() 44 { 45 ::EnterCriticalSection(&crit_section_); 46 } 47 48 // Unlock the mutex. unlockboost::asio::detail::win_static_mutex49 void unlock() 50 { 51 ::LeaveCriticalSection(&crit_section_); 52 } 53 54 bool initialised_; 55 ::CRITICAL_SECTION crit_section_; 56 }; 57 58 #if defined(UNDER_CE) 59 # define BOOST_ASIO_WIN_STATIC_MUTEX_INIT { false, { 0, 0, 0, 0, 0 } } 60 #else // defined(UNDER_CE) 61 # define BOOST_ASIO_WIN_STATIC_MUTEX_INIT { false, { 0, 0, 0, 0, 0, 0 } } 62 #endif // defined(UNDER_CE) 63 64 } // namespace detail 65 } // namespace asio 66 } // namespace boost 67 68 #include <boost/asio/detail/pop_options.hpp> 69 70 #if defined(BOOST_ASIO_HEADER_ONLY) 71 # include <boost/asio/detail/impl/win_static_mutex.ipp> 72 #endif // defined(BOOST_ASIO_HEADER_ONLY) 73 74 #endif // defined(BOOST_ASIO_WINDOWS) 75 76 #endif // BOOST_ASIO_DETAIL_WIN_STATIC_MUTEX_HPP 77