std_mutex.hpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. //
  2. // detail/std_mutex.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2023 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 ASIO_DETAIL_STD_MUTEX_HPP
  11. #define 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 "asio/detail/config.hpp"
  16. #include <mutex>
  17. #include "asio/detail/noncopyable.hpp"
  18. #include "asio/detail/scoped_lock.hpp"
  19. #include "asio/detail/push_options.hpp"
  20. namespace asio {
  21. namespace detail {
  22. class std_event;
  23. class std_mutex
  24. : private noncopyable
  25. {
  26. public:
  27. typedef asio::detail::scoped_lock<std_mutex> scoped_lock;
  28. // Constructor.
  29. std_mutex()
  30. {
  31. }
  32. // Destructor.
  33. ~std_mutex()
  34. {
  35. }
  36. // Lock the mutex.
  37. void lock()
  38. {
  39. mutex_.lock();
  40. }
  41. // Unlock the mutex.
  42. void unlock()
  43. {
  44. mutex_.unlock();
  45. }
  46. private:
  47. friend class std_event;
  48. std::mutex mutex_;
  49. };
  50. } // namespace detail
  51. } // namespace asio
  52. #include "asio/detail/pop_options.hpp"
  53. #endif // ASIO_DETAIL_STD_MUTEX_HPP