win_static_mutex.hpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. //
  2. // detail/win_static_mutex.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2018 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. #ifndef BOOST_ASIO_DETAIL_WIN_STATIC_MUTEX_HPP
  11. #define BOOST_ASIO_DETAIL_WIN_STATIC_MUTEX_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include <boost/asio/detail/config.hpp>
  16. #if defined(BOOST_ASIO_WINDOWS)
  17. #include <boost/asio/detail/scoped_lock.hpp>
  18. #include <boost/asio/detail/push_options.hpp>
  19. namespace boost {
  20. namespace asio {
  21. namespace detail {
  22. struct win_static_mutex
  23. {
  24. typedef boost::asio::detail::scoped_lock<win_static_mutex> scoped_lock;
  25. // Initialise the mutex.
  26. BOOST_ASIO_DECL void init();
  27. // Initialisation must be performed in a separate function to the "public"
  28. // init() function since the compiler does not support the use of structured
  29. // exceptions and C++ exceptions in the same function.
  30. BOOST_ASIO_DECL int do_init();
  31. // Lock the mutex.
  32. void lock()
  33. {
  34. ::EnterCriticalSection(&crit_section_);
  35. }
  36. // Unlock the mutex.
  37. void unlock()
  38. {
  39. ::LeaveCriticalSection(&crit_section_);
  40. }
  41. bool initialised_;
  42. ::CRITICAL_SECTION crit_section_;
  43. };
  44. #if defined(UNDER_CE)
  45. # define BOOST_ASIO_WIN_STATIC_MUTEX_INIT { false, { 0, 0, 0, 0, 0 } }
  46. #else // defined(UNDER_CE)
  47. # define BOOST_ASIO_WIN_STATIC_MUTEX_INIT { false, { 0, 0, 0, 0, 0, 0 } }
  48. #endif // defined(UNDER_CE)
  49. } // namespace detail
  50. } // namespace asio
  51. } // namespace boost
  52. #include <boost/asio/detail/pop_options.hpp>
  53. #if defined(BOOST_ASIO_HEADER_ONLY)
  54. # include <boost/asio/detail/impl/win_static_mutex.ipp>
  55. #endif // defined(BOOST_ASIO_HEADER_ONLY)
  56. #endif // defined(BOOST_ASIO_WINDOWS)
  57. #endif // BOOST_ASIO_DETAIL_WIN_STATIC_MUTEX_HPP