std_mutex.hpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. //
  2. // detail/std_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_STD_MUTEX_HPP
  11. #define BOOST_ASIO_DETAIL_STD_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_mutex
  26. : private noncopyable
  27. {
  28. public:
  29. typedef boost::asio::detail::scoped_lock<std_mutex> scoped_lock;
  30. // Constructor.
  31. std_mutex()
  32. {
  33. }
  34. // Destructor.
  35. ~std_mutex()
  36. {
  37. }
  38. // Lock the mutex.
  39. void lock()
  40. {
  41. mutex_.lock();
  42. }
  43. // Unlock the mutex.
  44. void unlock()
  45. {
  46. mutex_.unlock();
  47. }
  48. private:
  49. friend class std_event;
  50. std::mutex mutex_;
  51. };
  52. } // namespace detail
  53. } // namespace asio
  54. } // namespace boost
  55. #include <boost/asio/detail/pop_options.hpp>
  56. #endif // defined(BOOST_ASIO_HAS_STD_MUTEX_AND_CONDVAR)
  57. #endif // BOOST_ASIO_DETAIL_STD_MUTEX_HPP