std_static_mutex.hpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. //
  2. // detail/std_static_mutex.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2021 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_STD_STATIC_MUTEX_HPP
  11. #define BOOST_ASIO_DETAIL_STD_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_HAS_STD_MUTEX_AND_CONDVAR)
  17. #include <mutex>
  18. #include <boost/asio/detail/noncopyable.hpp>
  19. #include <boost/asio/detail/scoped_lock.hpp>
  20. #include <boost/asio/detail/push_options.hpp>
  21. namespace boost {
  22. namespace asio {
  23. namespace detail {
  24. class std_event;
  25. class std_static_mutex
  26. : private noncopyable
  27. {
  28. public:
  29. typedef boost::asio::detail::scoped_lock<std_static_mutex> scoped_lock;
  30. // Constructor.
  31. std_static_mutex(int)
  32. {
  33. }
  34. // Destructor.
  35. ~std_static_mutex()
  36. {
  37. }
  38. // Initialise the mutex.
  39. void init()
  40. {
  41. // Nothing to do.
  42. }
  43. // Lock the mutex.
  44. void lock()
  45. {
  46. mutex_.lock();
  47. }
  48. // Unlock the mutex.
  49. void unlock()
  50. {
  51. mutex_.unlock();
  52. }
  53. private:
  54. friend class std_event;
  55. std::mutex mutex_;
  56. };
  57. #define BOOST_ASIO_STD_STATIC_MUTEX_INIT 0
  58. } // namespace detail
  59. } // namespace asio
  60. } // namespace boost
  61. #include <boost/asio/detail/pop_options.hpp>
  62. #endif // defined(BOOST_ASIO_HAS_STD_MUTEX_AND_CONDVAR)
  63. #endif // BOOST_ASIO_DETAIL_STD_STATIC_MUTEX_HPP