Chris@16: // Chris@16: // detail/win_static_mutex.hpp Chris@16: // ~~~~~~~~~~~~~~~~~~~~~~~~~~~ Chris@16: // Chris@101: // Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com) Chris@16: // Chris@16: // Distributed under the Boost Software License, Version 1.0. (See accompanying Chris@16: // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: // Chris@16: Chris@16: #ifndef BOOST_ASIO_DETAIL_WIN_STATIC_MUTEX_HPP Chris@16: #define BOOST_ASIO_DETAIL_WIN_STATIC_MUTEX_HPP Chris@16: Chris@16: #if defined(_MSC_VER) && (_MSC_VER >= 1200) Chris@16: # pragma once Chris@16: #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) Chris@16: Chris@16: #include Chris@16: Chris@16: #if defined(BOOST_ASIO_WINDOWS) Chris@16: Chris@16: #include Chris@16: Chris@16: #include Chris@16: Chris@16: namespace boost { Chris@16: namespace asio { Chris@16: namespace detail { Chris@16: Chris@16: struct win_static_mutex Chris@16: { Chris@16: typedef boost::asio::detail::scoped_lock scoped_lock; Chris@16: Chris@16: // Initialise the mutex. Chris@16: BOOST_ASIO_DECL void init(); Chris@16: Chris@16: // Initialisation must be performed in a separate function to the "public" Chris@16: // init() function since the compiler does not support the use of structured Chris@16: // exceptions and C++ exceptions in the same function. Chris@16: BOOST_ASIO_DECL int do_init(); Chris@16: Chris@16: // Lock the mutex. Chris@16: void lock() Chris@16: { Chris@16: ::EnterCriticalSection(&crit_section_); Chris@16: } Chris@16: Chris@16: // Unlock the mutex. Chris@16: void unlock() Chris@16: { Chris@16: ::LeaveCriticalSection(&crit_section_); Chris@16: } Chris@16: Chris@16: bool initialised_; Chris@16: ::CRITICAL_SECTION crit_section_; Chris@16: }; Chris@16: Chris@16: #if defined(UNDER_CE) Chris@16: # define BOOST_ASIO_WIN_STATIC_MUTEX_INIT { false, { 0, 0, 0, 0, 0 } } Chris@16: #else // defined(UNDER_CE) Chris@16: # define BOOST_ASIO_WIN_STATIC_MUTEX_INIT { false, { 0, 0, 0, 0, 0, 0 } } Chris@16: #endif // defined(UNDER_CE) Chris@16: Chris@16: } // namespace detail Chris@16: } // namespace asio Chris@16: } // namespace boost Chris@16: Chris@16: #include Chris@16: Chris@16: #if defined(BOOST_ASIO_HEADER_ONLY) Chris@16: # include Chris@16: #endif // defined(BOOST_ASIO_HEADER_ONLY) Chris@16: Chris@16: #endif // defined(BOOST_ASIO_WINDOWS) Chris@16: Chris@16: #endif // BOOST_ASIO_DETAIL_WIN_STATIC_MUTEX_HPP